2017-12-24 14:17:18 +00:00
|
|
|
<?php
|
|
|
|
|
2017-12-30 20:23:09 +00:00
|
|
|
namespace App\Models;
|
2017-12-24 14:17:18 +00:00
|
|
|
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
2018-01-27 10:35:56 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2017-12-24 14:17:18 +00:00
|
|
|
|
|
|
|
class User extends Authenticatable
|
|
|
|
{
|
2018-01-27 10:35:56 +00:00
|
|
|
use Notifiable {
|
|
|
|
notify as protected laravelNotify;
|
|
|
|
}
|
2017-12-24 14:17:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = [
|
2017-12-30 20:23:09 +00:00
|
|
|
'name', 'email', 'password', 'introduction', 'avatar '
|
2017-12-24 14:17:18 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $hidden = [
|
|
|
|
'password', 'remember_token',
|
|
|
|
];
|
2017-12-30 20:23:09 +00:00
|
|
|
|
|
|
|
public function getHeaderAttribute()
|
|
|
|
{
|
|
|
|
return asset($this->avatar);
|
|
|
|
}
|
2018-01-01 07:32:35 +00:00
|
|
|
|
2018-01-01 13:22:16 +00:00
|
|
|
public function isAuthorOf($model)
|
|
|
|
{
|
|
|
|
return $this->id == $model->user_id;
|
|
|
|
}
|
|
|
|
|
2018-01-15 15:24:11 +00:00
|
|
|
public function replies()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Reply::class, 'user_id');
|
|
|
|
}
|
|
|
|
|
2018-01-01 07:32:35 +00:00
|
|
|
public function topics()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Topic::class);
|
|
|
|
}
|
2018-01-27 10:35:56 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2017-12-24 14:17:18 +00:00
|
|
|
}
|