62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Scopes\BelongsToPlanner;
|
|
use Carbon\Carbon;
|
|
use Closure;
|
|
use Database\Factories\ScheduleFactory;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Query\Builder;
|
|
use Illuminate\Database\Query\Expression;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property int $planner_id
|
|
* @property int $dish_id
|
|
* @property int $user_id
|
|
* @property Planner $planner
|
|
* @property Dish $dish
|
|
* @property User $user
|
|
* @property Carbon $date
|
|
* @property boolean $is_skipped
|
|
* @property Collection<ScheduledUserDish> $scheduledUserDishes
|
|
* @method static create(array $array)
|
|
* @method static Builder where(array|Closure|Expression|string $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
|
|
* @method static ScheduleFactory factory($count = null, $state = [])
|
|
* @method static firstOrCreate(array $array, false[] $array1)
|
|
*/
|
|
class Schedule extends Model
|
|
{
|
|
/** @use HasFactory<ScheduleFactory> */
|
|
use HasFactory;
|
|
|
|
protected $table = 'schedules';
|
|
|
|
public $timestamps = false;
|
|
|
|
protected $fillable = ['planner_id', 'date', 'is_skipped'];
|
|
|
|
protected $casts = [
|
|
'date' => 'date',
|
|
'is_skipped' => 'boolean',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::addGlobalScope(new BelongsToPlanner);
|
|
}
|
|
|
|
public function scheduledUserDishes(): HasMany
|
|
{
|
|
return $this->hasMany(ScheduledUserDish::class);
|
|
}
|
|
|
|
public function hasAllUsersScheduled(): bool
|
|
{
|
|
return $this->scheduledUserDishes->count() === User::where('planner_id', $this->planner_id)->count();
|
|
}
|
|
}
|