headlesslaravel / formations

MIT License
3 stars 5 forks source link

Exports #76

Closed dillingham closed 2 years ago

dillingham commented 2 years ago

Lets make a export feature

Route::formation(PostFormation::class)->asExport()
GET /posts/export

Also support passing a columns parameter to only include specific columns:

GET /posts/export?columns=id,title

Add a default a formation export method to use index() fields:

public function export(): array
{
     return $this->index()
}

So the developer can override the method like so:

public function export()
{
     return [
         Field::make('id'),
         Field::make('title'),
         Field::make('author_name', 'author.name'),
     ];
}

Loop over fields in the export to get relationships to eagerload like I do here

id title author_name
1 Blog post Mitul

Lets mimic how Import works, making a default $export class on Formation

And use the formation information to make the export work like imports does

(it sets the formation on the route using ->defaults())

Lets write some tests to insure it works as expected.