Shows how to build nested resources using restaurant menus with categories and dishes. Both categories and dishes can be reordered directly in the Filament table.
In this project, we have two Models:
Here are the contents of both models with fields and relationships defined.
app/Models/Category.php
use App\Observers\CategoryObserver;use Illuminate\Database\Eloquent\Factories\HasFactory;use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Eloquent\Relations\HasMany;use Illuminate\Database\Eloquent\Attributes\ObservedBy; #[ObservedBy(CategoryObserver::class)]class Category extends Model{ use HasFactory; protected $fillable = ['name', 'position']; public function dishes(): HasMany { return $this->hasMany(Dish::class); }}
app/Models/Dish.php
use App\Observers\DishObserver;use Illuminate\Database\Eloquent\Factories\HasFactory;use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Eloquent\Relations\BelongsTo;use Illuminate\Database\Eloquent\Attributes\ObservedBy; #[ObservedBy(DishObserver::class)]class Dish extends Model{ // ...
Next, we will: