Automatically generating forms and tables | doctrine/dbal

Sometimes this command generate the form and table data. But most of the time it's not work. I installed the
docrine/dbal
docrine/dbal
package and give protected_fillable data to model, but it's still not working. What should I do to find the problem? Why this command not generating the data automatically?
php artisan make:filament-resource Customer --generate
php artisan make:filament-resource Customer --generate
Solution:
yes, the generator looks at the DB table, not Model. so make sure to run migration before filament:resource --generate , you can add --force flag to replace the generated resource
Jump to solution
12 Replies
toeknee
toeknee8mo ago
Did you build out the model first?
Abdur Razzaque
Abdur Razzaque8mo ago
Yes This is my Gallery Model.
// Gallery.php
use HasFactory;
protected $fillable = [
'title',
'description',
'cover_image',
'images',
'status'
];
// Gallery.php
use HasFactory;
protected $fillable = [
'title',
'description',
'cover_image',
'images',
'status'
];
If I run the command
php artisan make:filament-resource Gallery --generate
php artisan make:filament-resource Gallery --generate
It's create this GalleryResource
// GalleryResource.php

class GalleryResource extends Resource
{
protected static ?string $model = Gallery::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form
{
return $form
->schema([
//
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
//
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListGalleries::route('/'),
'create' => Pages\CreateGallery::route('/create'),
'edit' => Pages\EditGallery::route('/{record}/edit'),
];
}
}
// GalleryResource.php

class GalleryResource extends Resource
{
protected static ?string $model = Gallery::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form
{
return $form
->schema([
//
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
//
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListGalleries::route('/'),
'create' => Pages\CreateGallery::route('/create'),
'edit' => Pages\EditGallery::route('/{record}/edit'),
];
}
}
Where form schema and table columns is empty. @toeknee Can you help me to solve this?
toeknee
toeknee8mo ago
Please read the #✅┊rules and don't tag people unless they have asked you too or you are friends. What is your table structure? Are you using ENUMS?
Abdur Razzaque
Abdur Razzaque8mo ago
No, I don't have enums.
toeknee
toeknee8mo ago
Then I am unsure sorry. Is the model in: app\Models
Abdur Razzaque
Abdur Razzaque8mo ago
Yes! it's app\Models I'm sorry about that. I was think that you don't get my reply notifications, that's why I tagged you. I'm sorry for tag you.
toeknee
toeknee8mo ago
We are not paid support, so if we don't get the notification that's fine. We will get round to it when we can.
Abdur Razzaque
Abdur Razzaque8mo ago
That's fine. You can ignore it.
ChesterS
ChesterS8mo ago
@Abdur Razzaque How do you define the status column in the database? Can you show the migration for that table/column? Also, do you get an error or does it just fail?
Alex Six
Alex Six8mo ago
I see that you've created your Model file with the $fillable array, but have you also created your migration file and run it against your local database? I can't find documentation on this, so I very well might be misremembering, but I feel like I remember reading/learning that the resource generator looks at the DB table to attempt to figure out the form field types, not at the Model.
Solution
wyChoong
wyChoong8mo ago
yes, the generator looks at the DB table, not Model. so make sure to run migration before filament:resource --generate , you can add --force flag to replace the generated resource
Abdur Razzaque
Abdur Razzaque8mo ago
I've already resolved my issue, but I wasn't aware of the logical cause of the database table. I thought the command worked through the model. This command functions properly after executing the migration command, i.e,
php artisan migrate
php artisan migrate