100 lines
2.2 KiB
PHP
100 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use App\Enums\UserRoles;
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\DatabaseNotification;
|
|
use Illuminate\Notifications\DatabaseNotificationCollection;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
/**
|
|
* @mixin IdeHelperUser
|
|
*/
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasFactory;
|
|
|
|
use Notifiable;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'city',
|
|
'mobile_number',
|
|
'role',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for serialization.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'role' => UserRoles::class,
|
|
];
|
|
}
|
|
|
|
public function favoriteProducts(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Product::class, 'favorite_products', 'user_id', 'product_id');
|
|
}
|
|
|
|
public function hasFavorited(Product $product): bool
|
|
{
|
|
return $this->favoriteProducts()->where('product_id', $product->id)->exists();
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<Cart>
|
|
*/
|
|
public function carts():HasMany
|
|
{
|
|
return $this->hasMany(Cart::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsToMany<Address>
|
|
*/
|
|
public function addresses(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Address::class);
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<Order>
|
|
*/
|
|
public function orders(): HasMany
|
|
{
|
|
return $this->hasMany(Order::class);
|
|
}
|
|
}
|