File: D:/HostingSpaces/MdnDirecteur/hours.komma.cloud/app/Komma/Users/User.php
<?php
namespace App\Komma\Users;
use App\Komma\ActivityLog\Activity;
use App\Komma\Hours\Hour;
use App\Komma\ProjectWorkers\ProjectWorker;
use App\Komma\Roles\Role;
use App\Mail\SendPasswordResetMail;
use Illuminate\Auth\Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Support\Facades\Mail;
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword, SoftDeletes, Notifiable;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'email', 'password', 'contract', 'factTarget', 'prodTarget'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function Hours()
{
return $this->hasMany(Hour::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function ProjectWorkers()
{
return $this->hasMany(ProjectWorker::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function Activity()
{
return $this->hasMany(Activity::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function Roles()
{
return $this->belongsToMany(Role::class);
}
/**
* @return bool
*/
public function isAdmin()
{
if($this->Roles->where('name', '=', 'admin')->count() == 0 ) return false;
return true;
}
/**
* @param $role
* @return bool
*/
public function hasRole($role)
{
if (is_string($role)) {
return $this->Roles->contains($role, 'name');
}
return !!$role->intersect($this->Roles)->count();
}
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function Activities()
{
return $this->morphMany('App\Komma\ActivityLog\Activity', 'subject');
}
protected $dates = ['deleted_at'];
/**
* Send the password reset mail.
*
* @param string $token
*/
public function sendPasswordResetNotification($token)
{
Mail::to($this->email)->send(new SendPasswordResetMail($this, route('password.reset', $token, true)));
}
}