*/ protected $fillable = [ 'name', 'surname', 'patronymic', 'phone_number', 'email', 'password', 'role', 'warehouse_id', ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', 'password' => 'hashed', 'role' => RoleEnum::class, ]; public function car(): HasOne { return $this->hasOne(Car::class); } public function deliveries(): HasMany { return $this->hasMany(Delivery::class); } public function warehouse(): BelongsTo { return $this->belongsTo(Warehouse::class); } protected function fio(): Attribute { return Attribute::make( get: fn () => $this->surname . ' ' . $this->name . ' ' . $this->patronymic, ); } public function scopeFilter(Builder $query): void { $name = request('name'); $query->when($name, function (Builder $query, $name) { $query->whereRaw('CONCAT (name, \' \', surname, \' \', patronymic) ilike ?', ["$name%"]); $query->orWhereRaw('CONCAT (name, \' \', patronymic, \' \', surname) ilike ?', ["$name%"]); $query->orWhereRaw('CONCAT (surname, \' \', name, \' \', patronymic) ilike ?', ["$name%"]); $query->orWhereRaw('CONCAT (surname, \' \', patronymic, \' \', name) ilike ?', ["$name%"]); $query->orWhereRaw('CONCAT (patronymic, \' \', name, \' \', surname) ilike ?', ["$name%"]); $query->orWhereRaw('CONCAT (patronymic, \' \', surname, \' \', name) ilike ?', ["$name%"]); })->paginate(10)->withQueryString(); } }