| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
-
- namespace App\Models;
-
- use Illuminate\Contracts\Auth\MustVerifyEmail;
- use Illuminate\Database\Eloquent\Casts\Attribute;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- use Illuminate\Notifications\Notifiable;
- use Laravel\Sanctum\HasApiTokens;
-
- class User extends Authenticatable implements MustVerifyEmail
- {
- use HasApiTokens, HasFactory, Notifiable;
-
- /**
- * The attributes that are mass assignable.
- *
- * @var array<int, string>
- */
- protected $fillable = [
- 'name',
- 'phone',
- 'email',
- 'status',
- 'password',
- 'role_id',
- ];
-
- /**
- * The attributes that should be hidden for serialization.
- *
- * @var array<int, string>
- */
- protected $hidden = [
- 'password',
- 'remember_token',
- ];
-
- /**
- * The attributes that should be cast.
- *
- * @var array<string, string>
- */
- protected $casts = [
- 'email_verified_at' => 'datetime',
- ];
-
- protected function status(): Attribute
- {
- return Attribute::make(
- get:fn($value) => $value ? __('words.active') : __('words.not_active'),
- );
- }
-
- public function role()
- {
- return $this->belongsTo(Role::class);
- }
-
- public function scopeFilter($query, array $filters)
- {
- $query->when($filters['search'] ?? null, function ($query, $search) {
- $query->where(function ($query) use ($search) {
- $query->where('name', 'like', '%' . $search . '%')
- ->orWhere('email', 'like', '%' . $search . '%');
- });
- });
- }
- }
|