© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
3 replies
Mr. Phearum

Category with Parent_id

public function up(): void
{
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->foreignId('team_id')->constrained('teams');
$table->string('name');
$table->string('slug')->unique();
$table->foreignId('parent_id')->nullable()->constrained('categories');
$table->string('image')->nullable();
$table->boolean('active')->default(true);
$table->longText('description')->nullable();
$table->timestamps();
});
}

protected $fillable =[
'team_id',
'name',
'slug',
'parent_id',
'image',
'active',
'description',
];

public function team(): BelongsTo
{
return $this->belongsTo(Team::class);
}

public function parent(): BelongsTo
{
return $this->belongsTo(Category::class, 'parent_id');
}

public function child():HasMany {

return $this->hasMany(Category::class, 'parent_id');
}

public function products() : BelongsToMany
{
return $this->belogsToMany(Product::class);
}


We get errors like the picture attached.
17-Dec-2023_10-22-32_PM.png
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Select::make('category_id') VS. Select::make('Category')
FilamentFFilament / ❓┊help
11mo ago
check parent category and it checks children categories
FilamentFFilament / ❓┊help
2y ago
Create Comment - where to inject parent ID?
FilamentFFilament / ❓┊help
16mo ago
Passing parent id to child create view
FilamentFFilament / ❓┊help
3y ago