composer require ldc/web-status-checker-laravel remove Old static status checker Fix ImportMedia WIP commands OK many fixes Fix and try to optimize folder component Fix front icons + actions based on icons Favico front fix alert Fix Media upload on depot fix folder component buttons Full front fix with perf due tu vuejs Download medias Navigate within medias superfix Move media + loader isLocked boolean and remove media fix Folder scroll fix arcadia link color red Fix panier show external Tons of fixes back as front REwrited all
176 lines
3.8 KiB
PHP
176 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
use HasFactory;
|
|
use Notifiable;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
];
|
|
|
|
/**
|
|
* 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',
|
|
];
|
|
|
|
// * METHODS
|
|
|
|
/**
|
|
* Authorize role
|
|
*
|
|
* @param string|array $roles
|
|
* @return boolean
|
|
*/
|
|
public function authorizeRoles($roles): bool
|
|
{
|
|
if (is_array($roles) and in_array($this->role, $roles)) {
|
|
return true;
|
|
}
|
|
if (is_string($roles) and $this->role == $roles) {
|
|
return true;
|
|
}
|
|
abort(401, 'Cette action n\'est pas autorisée.');
|
|
}
|
|
|
|
/**
|
|
* Check one role
|
|
*
|
|
* @param array|string $roles
|
|
* @return boolean
|
|
*/
|
|
public function hasRole($roles): bool
|
|
{
|
|
if (is_array($roles)) {
|
|
return in_array($this->role, $roles);
|
|
}
|
|
return $this->role == $roles;
|
|
}
|
|
|
|
/**
|
|
* Get role label
|
|
*
|
|
* @return string|null
|
|
*/
|
|
public function getRoleLabel(): ?string
|
|
{
|
|
return config('roles.label.' . $this->role);
|
|
}
|
|
|
|
// * 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);
|
|
}
|
|
|
|
/**
|
|
* 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 media relation
|
|
* Get the media for the user.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function mediaList()
|
|
{
|
|
return $this->hasMany(Media::class);
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
}
|