75 lines
1.4 KiB
PHP
75 lines
1.4 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Models;
|
||
|
|
||
|
use Cviebrock\EloquentSluggable\Sluggable;
|
||
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||
|
use Illuminate\Notifications\Notifiable;
|
||
|
use Illuminate\Support\Facades\Storage;
|
||
|
|
||
|
class User extends Authenticatable
|
||
|
{
|
||
|
use Notifiable, Sluggable;
|
||
|
|
||
|
/**
|
||
|
* The attributes that are mass assignable.
|
||
|
*
|
||
|
* @var array
|
||
|
*/
|
||
|
protected $fillable = [
|
||
|
'avatar', 'avatar_rating', 'user_verified_at', 'name', 'email', 'password',
|
||
|
];
|
||
|
|
||
|
/**
|
||
|
* The attributes that should be hidden for arrays.
|
||
|
*
|
||
|
* @var array
|
||
|
*/
|
||
|
protected $hidden = [
|
||
|
'password', 'remember_token',
|
||
|
];
|
||
|
|
||
|
/**
|
||
|
* The attributes that should be cast to native types.
|
||
|
*
|
||
|
* @var array
|
||
|
*/
|
||
|
protected $casts = [
|
||
|
'email_verified_at' => 'datetime',
|
||
|
];
|
||
|
|
||
|
public function books()
|
||
|
{
|
||
|
return $this->hasMany(Book::class);
|
||
|
}
|
||
|
|
||
|
public function comments()
|
||
|
{
|
||
|
return $this->hasMany(Comment::class);
|
||
|
}
|
||
|
|
||
|
public function getRouteKeyName()
|
||
|
{
|
||
|
return 'slug';
|
||
|
}
|
||
|
|
||
|
public function sluggable()
|
||
|
{
|
||
|
return [
|
||
|
'slug' => [
|
||
|
'source' => 'name'
|
||
|
]
|
||
|
];
|
||
|
}
|
||
|
|
||
|
public function UserAvatar(){
|
||
|
if(is_null($this->avatar)){
|
||
|
$url = asset('images/default-avatar.jpg');
|
||
|
}
|
||
|
else {
|
||
|
$url = url(Storage::url($this->avatar));
|
||
|
}
|
||
|
return $url;
|
||
|
}
|
||
|
}
|