Update Profile model

This commit is contained in:
Daniel Supernault 2018-05-22 17:56:20 -06:00
parent 18b712e790
commit e395a9b0f6

View file

@ -3,12 +3,30 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Storage;
class Profile extends Model
{
public function url()
protected $hidden = [
'private_key',
];
protected $visible = ['id', 'username', 'name'];
public function url($suffix = '')
{
return url('/' . $this->username);
return url('/@' . $this->username . $suffix);
}
public function permalink($suffix = '')
{
return url('users/' . $this->username . $suffix);
}
public function emailUrl()
{
$domain = parse_url(config('app.url'), PHP_URL_HOST);
return $this->username . '@' . $domain;
}
public function statuses()
@ -44,4 +62,15 @@ class Profile extends Model
{
return $this->hasMany(Like::class);
}
public function avatar()
{
return $this->hasOne(Avatar::class);
}
public function avatarUrl()
{
$url = url(Storage::url($this->avatar->media_path ?? 'public/avatars/default.png'));
return $url;
}
}