dishplanner/app/Models/ScheduledUserDish.php

53 lines
1.3 KiB
PHP
Raw Normal View History

2025-10-13 14:57:11 +02:00
<?php
namespace App\Models;
use Database\Factories\ScheduledUserDishFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* @property int $id
* @property int $schedule_id
* @property Schedule $schedule
* @property int $user_dish_id
* @property UserDish $userDish
* @property bool $is_skipped
* @method static create(array $array)
* @method static ScheduledUserDishFactory factory($count = null, $state = [])
*/
class ScheduledUserDish extends Model
{
use HasFactory;
protected $fillable = ['schedule_id', 'user_id', 'user_dish_id', 'is_skipped'];
protected $casts = [
'is_skipped' => 'boolean',
];
public function schedule(): BelongsTo
{
return $this->belongsTo(Schedule::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function userDish(): BelongsTo
{
return $this->belongsTo(UserDish::class);
}
public function scopeForUser(Builder $query, int $userId): Builder
{
return $query->whereHas('userDish', function (Builder $query) use ($userId) {
$query->where('user_id', $userId);
});
}
}