pixelfed/app/Profile.php

77 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
2018-05-22 23:56:20 +00:00
use Storage;
class Profile extends Model
{
2018-05-22 23:56:20 +00:00
protected $hidden = [
'private_key',
];
protected $visible = ['id', 'username', 'name'];
public function url($suffix = '')
2018-04-19 05:57:16 +00:00
{
2018-05-22 23:56:20 +00:00
return url('/@' . $this->username . $suffix);
}
public function permalink($suffix = '')
{
return url('users/' . $this->username . $suffix);
2018-04-19 05:57:16 +00:00
}
2018-05-22 23:56:20 +00:00
public function emailUrl()
{
$domain = parse_url(config('app.url'), PHP_URL_HOST);
return $this->username . '@' . $domain;
}
public function statuses()
{
return $this->hasMany(Status::class);
}
public function following()
{
return $this->hasManyThrough(
Profile::class,
Follower::class,
'profile_id',
'id',
'id',
'id'
);
}
public function followers()
{
return $this->hasManyThrough(
Profile::class,
Follower::class,
'following_id',
'id',
'id',
'id'
);
}
2018-04-19 05:57:16 +00:00
public function likes()
{
return $this->hasMany(Like::class);
}
2018-05-22 23:56:20 +00:00
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;
}
}