mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Add new methods to Status model
This commit is contained in:
parent
b8033f4a70
commit
33af3cfe96
1 changed files with 31 additions and 1 deletions
|
@ -3,8 +3,38 @@
|
|||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Storage;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class Status extends Model
|
||||
{
|
||||
//
|
||||
public function profile()
|
||||
{
|
||||
return $this->belongsTo(Profile::class);
|
||||
}
|
||||
|
||||
public function media()
|
||||
{
|
||||
return $this->hasMany(Media::class);
|
||||
}
|
||||
|
||||
public function firstMedia()
|
||||
{
|
||||
return $this->hasMany(Media::class)->orderBy('order', 'asc')->first();
|
||||
}
|
||||
|
||||
public function url()
|
||||
{
|
||||
$hid = Hashids::encode($this->id);
|
||||
$username = $this->profile->username;
|
||||
return url("/p/@{$username}/{$hid}");
|
||||
}
|
||||
|
||||
public function mediaUrl()
|
||||
{
|
||||
$path = $this->firstMedia()->media_path;
|
||||
$url = Storage::url($path);
|
||||
return url($url);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue