2025-10-13 14:57:11 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use App\Models\Scopes\BelongsToPlanner;
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
use Database\Factories\DishFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @property int $id
|
|
|
|
|
* @property int $planner_id
|
|
|
|
|
* @property string $name
|
|
|
|
|
* @property int $recurrence
|
|
|
|
|
* @property Carbon $created_at
|
|
|
|
|
* @property Carbon $updated_at
|
|
|
|
|
* @property Collection<User> $users
|
|
|
|
|
* @property Collection<UserDish> $userDishes
|
2026-08-17 13:30:49 +02:00
|
|
|
*
|
2025-10-13 14:57:11 +02:00
|
|
|
* @method static create(array $data)
|
|
|
|
|
* @method static findOrFail(int $dish_id)
|
|
|
|
|
* @method static DishFactory factory($count = null, $state = [])
|
|
|
|
|
*/
|
|
|
|
|
class Dish extends Model
|
|
|
|
|
{
|
|
|
|
|
/** @use HasFactory<DishFactory> */
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
|
|
protected $fillable = ['planner_id', 'name', 'recurrence'];
|
|
|
|
|
|
|
|
|
|
protected $casts = [];
|
|
|
|
|
|
|
|
|
|
protected static function booted(): void
|
|
|
|
|
{
|
|
|
|
|
static::addGlobalScope(new BelongsToPlanner);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function users(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(User::class, 'user_dishes', 'dish_id', 'user_id')
|
|
|
|
|
->orderBy('name');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function userDishes(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(UserDish::class, 'dish_id', 'id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function recurrences(): HasManyThrough
|
|
|
|
|
{
|
|
|
|
|
return $this->hasManyThrough(
|
|
|
|
|
UserDishRecurrence::class,
|
|
|
|
|
UserDish::class,
|
|
|
|
|
'dish_id',
|
|
|
|
|
'user_dish_id',
|
|
|
|
|
'id',
|
|
|
|
|
'id'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|