2018-04-16 01:18:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2018-04-17 01:24:18 +00:00
|
|
|
use Storage;
|
|
|
|
use Vinkla\Hashids\Facades\Hashids;
|
2018-04-16 01:18:59 +00:00
|
|
|
|
|
|
|
class Status extends Model
|
|
|
|
{
|
2018-04-17 01:24:18 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-04-17 01:35:18 +00:00
|
|
|
public function likes()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Like::class);
|
|
|
|
}
|
|
|
|
|
2018-04-19 05:57:24 +00:00
|
|
|
public function comments()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Comment::class);
|
|
|
|
}
|
|
|
|
|
2018-04-16 01:18:59 +00:00
|
|
|
}
|