🔧 Filament: Generate Resource from Existing DB Schema
Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to
In Filament, you can generate a Filament Resource with the make:filament-resource
Artisan command.
This command will generate an empty resource, that you can configure it as you like.
If you already have the migration and model done in your Laravel app, you can use the parameter --generate
in order to let Filament try to guess the fields from your database.
php artisan make:filament-resource Model --generate
For example, if you have a Tag model with a name and description fields, running the following command:
php artisan make:filament-resource Tag --generate
Will generate the following resource:
class CategoryResource extends Resource
{
// ...
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('description')
->required()
->maxLength(255),
]);
}
// ...
}
You should keep in mind the generation will not always be accurate, so check the code and make any necessary changes to it.
...