74 lines
1.6 KiB
PHP
74 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
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
|
|
{
|
|
use HasApiTokens, HasFactory, Notifiable;
|
|
|
|
protected $table = 'user';
|
|
protected $primaryKey = 'username';
|
|
public $incrementing = false;
|
|
protected $keyType = 'string';
|
|
public $timestamps = false;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'username',
|
|
'email',
|
|
'password',
|
|
'phone_number',
|
|
'role',
|
|
'email_verified_at',
|
|
'login_otp',
|
|
'login_otp_expires_at',
|
|
];
|
|
|
|
/**
|
|
* 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',
|
|
'login_otp_expires_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
];
|
|
|
|
/**
|
|
* Get the user's favorite cars
|
|
*/
|
|
public function favorites()
|
|
{
|
|
return $this->hasMany(Favorite::class, 'username', 'username');
|
|
}
|
|
|
|
/**
|
|
* Get the categories that the user has favorited
|
|
*/
|
|
public function favoriteCategories()
|
|
{
|
|
return $this->belongsToMany(Category::class, 'favorites', 'username', 'category_id', 'username', 'id');
|
|
}
|
|
|
|
}
|