فهرست منبع

Add new methods to Status model

Daniel Supernault 7 سال پیش
والد
کامیت
33af3cfe96
1فایلهای تغییر یافته به همراه31 افزوده شده و 1 حذف شده
  1. 31 1
      app/Status.php

+ 31 - 1
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);
+    }
+
 }