headlesslaravel / formations

MIT License
3 stars 5 forks source link

Fields: only & except #124

Open dillingham opened 2 years ago

dillingham commented 2 years ago

Currently to define index fields or form fields, we have to define a method index() show create edit

and in those formation methods, we return an array of fields.. which get passed to the frontend via meta()

public function index(): array
{
    return [
        Field::make('ID'),
        Field::make('Title'),
        Field::make('Created At'),
    ];
}

public function create(): array
{
    return [
        Field::make('Title'),
    ];
}
public function fields(): array
{
    return [
        Field::make('ID')->only(['index', 'show']),
        Field::make('Title'),
        Field::make('Created At')->except(['create', 'edit']),
    ];
}

Tests

Write a test that asserts fields are included or excluded depending on controller method / route.