Advertisement
Guest User

Untitled

a guest
Nov 13th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. class Reply extends Model
  2. {
  3.     protected $guarded = [];
  4.  
  5. //    protected $fillable = [
  6. //        'user_id', 'post_id', 'reply_text',
  7. //    ];
  8.  
  9.     public function user()
  10.     {
  11.         return $this->belongsTo('App\User');
  12.     }
  13.  
  14.     public function post()
  15.     {
  16.         return $this->belongsTo('App\Post');
  17.     }
  18.  
  19.     public function likes() {
  20.         return $this->morphMany('App\Like', 'liked');
  21.     }
  22.  
  23.     public function owner() {
  24.         return $this->belongsTo('App\User', 'user_id');
  25.     }
  26.  
  27.     public function like() {
  28.  
  29.         $userCheck = ['user_id' => auth()->id()];
  30.  
  31.         if (! $this->likes()->where($userCheck)->exists()) {
  32.             $this->likes()->create($userCheck);
  33.         }
  34.  
  35.     }
  36.  
  37.     public function isLiked() {
  38.         return $this->likes()->where('user_id', auth()->id())->exists();
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement