71 lines
1.4 KiB
PHP
71 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
use Notifiable {
|
|
notify as protected laravelNotify;
|
|
}
|
|
use HasRoles;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'name', 'email', 'password', 'introduction', 'avatar '
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
'password', 'remember_token',
|
|
];
|
|
|
|
public function getHeaderAttribute()
|
|
{
|
|
return asset($this->avatar);
|
|
}
|
|
|
|
public function isAuthorOf($model)
|
|
{
|
|
return $this->id == $model->user_id;
|
|
}
|
|
|
|
public function replies()
|
|
{
|
|
return $this->hasMany(Reply::class, 'user_id');
|
|
}
|
|
|
|
public function topics()
|
|
{
|
|
return $this->hasMany(Topic::class);
|
|
}
|
|
|
|
public function notify($instance)
|
|
{
|
|
if ($this->id == Auth::id()) {
|
|
return;
|
|
}
|
|
$this->increment('notification_count');
|
|
$this->laravelNotify($instance);
|
|
}
|
|
|
|
public function markAsRead()
|
|
{
|
|
$this->notification_count = 0;
|
|
$this->save();
|
|
$this->unreadNotifications->markAsRead();
|
|
}
|
|
}
|