I am beginner in Laravel. I use Laravel 5.8 in my project. I have this Model:
class User extends Authenticatable implements MustVerifyEmail
{
use Notifiable;
public static $roles = [];
protected $fillable = ['last_activity', 'enable', 'name', 'surname', 'email', 'email_verified_at', 'password', 'counter', 'url_address', 'isCompany', 'isMailing'];
protected $hidden = [
'password', 'remember_token',
];
public function roles()
{
return $this->belongsToMany('App\Role');
}
public function mainRole()
{
return $this->hasOne('App\Role');
}
public function comments()
{
return $this->hasMany('App\Comments');
}
public function hasRole(array $roles)
{
foreach ($roles as $role) {
if (isset(self::$roles[$role])) {
if (self::$roles[$role]) return true;
} else {
self::$roles[$role] = $this->roles()->where('name', $role)->exists();
if (self::$roles[$role]) return true;
}
}
return false;
}
public function loginHistory()
{
return $this->hasMany('App\UserLoginHistory');
}
public function companies()
{
return $this->belongsTo('App\Companies', 'company_id');
}
public function images()
{
return $this->hasManyThrough('App\UploadedFiles', 'App\User', 'id', 'photoable_id');
}
public function scopeOfRoleType($query, $types)
{
return $query->whereHas('roles', function ($q) use ($types) {
$q->whereIn('name', $types);
});
}
}
In last_activity - I have date for example 2019-07-16 10:26:12
I need show on my twig page:
@foreach ($usersList as $user)
User name: $user->name is now ...... (offline or online)
@endforeach
I would like to see if the user is online or offline.
I think about something like this:
public function isOnline()
{
return .....
}
but I do not know how to check this activity :(
Please help.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire