From 33af3cfe962e7c1e97cf2383f3cde8c31a97e86e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 16 Apr 2018 19:24:18 -0600 Subject: [PATCH] Add new methods to Status model --- app/Status.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/app/Status.php b/app/Status.php index 2e254e636..02a73767f 100644 --- a/app/Status.php +++ b/app/Status.php @@ -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); + } + }