2019-05-09 15:00:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
|
|
|
|
|
|
class User extends Authenticatable
|
|
|
|
|
{
|
|
|
|
|
use Notifiable;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2019-05-16 17:20:30 +02:00
|
|
|
// protected $fillable = [
|
|
|
|
|
// 'name', 'email', 'password',
|
|
|
|
|
// ];
|
2019-05-09 15:00:05 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $hidden = [
|
|
|
|
|
'password', 'remember_token',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that should be cast to native types.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'email_verified_at' => 'datetime',
|
|
|
|
|
];
|
2019-05-16 17:20:30 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string|array $roles
|
|
|
|
|
*/
|
|
|
|
|
public function authorizeRoles($roles){
|
|
|
|
|
if (is_array($roles)) {
|
|
|
|
|
return in_array($this->role, $roles) ||
|
|
|
|
|
abort(401, 'Cette action n\'est pas autorisée.');
|
|
|
|
|
}
|
|
|
|
|
return $this->role == $roles ||
|
|
|
|
|
abort(401, 'Cette action n\'est pas autorisée.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check one role
|
|
|
|
|
* @param string $role
|
|
|
|
|
*/
|
2019-05-22 17:10:16 +02:00
|
|
|
public function hasRole($roles) {
|
|
|
|
|
if (is_array($roles)) {
|
|
|
|
|
return in_array($this->role, $roles);
|
|
|
|
|
}
|
|
|
|
|
return $this->role == $roles;
|
2019-05-16 17:20:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* get one role label
|
|
|
|
|
* @param string $role
|
|
|
|
|
*/
|
|
|
|
|
public function getRoleLabel() {
|
|
|
|
|
return config('roles.label.'.$this->role);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The marques that belong to the user.
|
|
|
|
|
*/
|
|
|
|
|
public function marques()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany('App\Marque', 'marques_users', 'user_id', 'marque_id');
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-22 17:10:16 +02:00
|
|
|
/**
|
|
|
|
|
* The dossiers that belong to the user.
|
|
|
|
|
*/
|
|
|
|
|
public function dossiers()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany('App\Dossier', 'dossiers_users', 'user_id', 'dossier_id');
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-16 17:20:30 +02:00
|
|
|
/**
|
|
|
|
|
* The sujet that belong to the user.
|
|
|
|
|
*/
|
|
|
|
|
public function sujets()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany('App\Sujet', 'sujets_users', 'user_id', 'sujet_id');
|
|
|
|
|
}
|
2019-07-11 11:45:47 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the medias for the user.
|
|
|
|
|
*/
|
|
|
|
|
public function medias()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany('App\Media');
|
|
|
|
|
}
|
2019-07-22 14:54:42 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the historiques for the user.
|
|
|
|
|
*/
|
|
|
|
|
public function historiques()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany('App\Historique');
|
|
|
|
|
}
|
2019-07-25 09:43:06 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the recherches for the user.
|
|
|
|
|
*/
|
|
|
|
|
public function recherches()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany('App\Recherche');
|
|
|
|
|
}
|
2019-07-31 12:22:24 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the paniers for the user.
|
|
|
|
|
*/
|
|
|
|
|
public function paniersOwner()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany('App\Panier', 'owner');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The paniers that belong to the user.
|
|
|
|
|
*/
|
|
|
|
|
public function paniersFavoris()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany('App\Panier', 'paniers_users', 'user_id', 'panier_id');
|
|
|
|
|
}
|
2019-05-09 15:00:05 +02:00
|
|
|
}
|