F
Filament17mo ago
giro

Any example of a multilevel category?

If I have a model structure like this.
public function up(): void
{
Schema::create('categories', static function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table
->foreignId('parent_id')
->nullable()
->constrained('categories')
->onDelete('set null');
$table->timestamps();
});
}
public function up(): void
{
Schema::create('categories', static function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table
->foreignId('parent_id')
->nullable()
->constrained('categories')
->onDelete('set null');
$table->timestamps();
});
}
Any example how can I manage this with filament (List/Create)? Thanks.
Solution:
So if you are using parents and children, you would then select only the top level with a scope and apply that scope, or apply it to the getTableQuery(). Then you can build a relationship manager for the sub categories.
Jump to solution
3 Replies
toeknee
toeknee17mo ago
run: php artisan make:filament-resource Categories --generate or php artisan make:filament-resource Categories --simple if you want Modals.
giro
giroOP17mo ago
Okey, this I know. But for default It will list all categories, but categories have parents and childrens. How manage this on list?
Solution
toeknee
toeknee17mo ago
So if you are using parents and children, you would then select only the top level with a scope and apply that scope, or apply it to the getTableQuery(). Then you can build a relationship manager for the sub categories.
Want results from more Discord servers?
Add your server