2016-09-01 16:23:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
2017-09-10 17:02:15 +01:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2016-09-01 16:23:39 +01:00
|
|
|
|
|
|
|
class User extends Authenticatable
|
|
|
|
{
|
|
|
|
use Notifiable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = [
|
2017-04-18 17:25:27 +01:00
|
|
|
'name', 'email', 'password', 'is_admin', 'is_activated', 'activation_token'
|
2016-09-01 16:23:39 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $hidden = [
|
2016-09-06 12:23:14 +01:00
|
|
|
'password', 'remember_token', 'activation_token'
|
2016-09-01 16:23:39 +01:00
|
|
|
];
|
2016-09-21 12:10:37 +01:00
|
|
|
|
|
|
|
public static function administrators()
|
|
|
|
{
|
|
|
|
return User::where('is_admin', true)->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function anonymous()
|
|
|
|
{
|
|
|
|
$user = new User();
|
|
|
|
$user->id = -1;
|
|
|
|
$user->name = 'Anonymous';
|
|
|
|
|
|
|
|
return $user;
|
|
|
|
}
|
2017-02-14 11:03:58 +00:00
|
|
|
|
2017-09-10 17:02:15 +01:00
|
|
|
public static function currentOrAnonymous()
|
|
|
|
{
|
|
|
|
$user = Auth::user();
|
|
|
|
return (is_null($user)
|
|
|
|
? User::anonymous()
|
|
|
|
: $user);
|
|
|
|
}
|
|
|
|
|
2017-02-14 11:03:58 +00:00
|
|
|
public function groups()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(Group::class, 'user_groups');
|
|
|
|
}
|
2017-04-15 08:36:17 +01:00
|
|
|
|
|
|
|
public function isAnonymous()
|
|
|
|
{
|
|
|
|
return $this->id == -1 && $this->name == 'Anonymous';
|
|
|
|
}
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|