F
Filament12mo 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
toeknee12mo ago
run: php artisan make:filament-resource Categories --generate or php artisan make:filament-resource Categories --simple if you want Modals.
giro
giro12mo 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
toeknee12mo 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.