155 lines
4.6 KiB
PHP
155 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\Users\RoleEnum;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
/**
|
|
* @property string $firstname Prénom.
|
|
* @property string $lastname Nom.
|
|
* @property string $email Email.
|
|
* @property string $objectguid
|
|
* @property string $matricule Unique LDAP.
|
|
* @property-read \Illuminate\Support\Carbon $email_verified_at Mail verified at date.
|
|
* @property string $password Mot de passe.
|
|
* @property string $remember_token
|
|
* @property \App\Enums\Users\RoleEnum $role RoleEnum.
|
|
* @property-read \Illuminate\Support\Carbon $created_at Created date.
|
|
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
|
|
*
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Marque> $marques
|
|
* Marques BelongsToMany relationship.
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Dossier> $dossiers
|
|
* Dossiers BelongsToMany relationship.
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Sujet> $sujets
|
|
* Sujets BelongsToMany relationship.
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Historique> $historiques
|
|
* Historiques HasMany relationship.
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Recherche> $recherches
|
|
* Recherches HasMany relationship.
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Panier> $paniersOwner
|
|
* Paniers HasMany relationship that belongs to the user.
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Panier> $paniersFavoris
|
|
* Paniers HasMany relationship.
|
|
*/
|
|
class User extends Authenticatable
|
|
{
|
|
use HasFactory;
|
|
use Notifiable;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'matricule',
|
|
'firstname',
|
|
'lastname',
|
|
'email',
|
|
'password',
|
|
'role',
|
|
];
|
|
|
|
/**
|
|
* 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',
|
|
'role' => RoleEnum::class,
|
|
];
|
|
|
|
// * RELATIONSHIPS
|
|
|
|
/**
|
|
* BelongsToMany marque relation
|
|
* The marques that belong to the user.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function marques()
|
|
{
|
|
return $this->belongsToMany(Marque::class, 'marque_user', 'user_id', 'marque_id');
|
|
}
|
|
|
|
/**
|
|
* BelongsToMany dossier relation
|
|
* The dossiers that belong to the user.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function dossiers()
|
|
{
|
|
return $this->belongsToMany(Dossier::class);
|
|
}
|
|
|
|
/**
|
|
* BelongsToMany sujet relation
|
|
* The sujet that belong to the user.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function sujets()
|
|
{
|
|
return $this->belongsToMany(Sujet::class, 'sujet_user', 'user_id', 'sujet_id');
|
|
}
|
|
|
|
/**
|
|
* HasMany historiques relation
|
|
* Get the historiques for the user.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function historiques()
|
|
{
|
|
return $this->hasMany(Historique::class);
|
|
}
|
|
|
|
/**
|
|
* HasMany recherches relation
|
|
* Get the recherches for the user.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function recherches()
|
|
{
|
|
return $this->hasMany(Recherche::class);
|
|
}
|
|
|
|
/**
|
|
* HasMany paniers relation
|
|
* Get the paniers for the user.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function paniersOwner()
|
|
{
|
|
return $this->hasMany(Panier::class, 'user_id')->with('mediaList');
|
|
}
|
|
|
|
/**
|
|
* BelongsToMany paniers relation
|
|
* The paniers that belong to the user.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function paniersFavoris()
|
|
{
|
|
return $this->belongsToMany(Panier::class);
|
|
}
|
|
}
|