Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Reply extends Model
- {
- protected $guarded = [];
- // protected $fillable = [
- // 'user_id', 'post_id', 'reply_text',
- // ];
- public function user()
- {
- return $this->belongsTo('App\User');
- }
- public function post()
- {
- return $this->belongsTo('App\Post');
- }
- public function likes() {
- return $this->morphMany('App\Like', 'liked');
- }
- public function owner() {
- return $this->belongsTo('App\User', 'user_id');
- }
- public function like() {
- $userCheck = ['user_id' => auth()->id()];
- if (! $this->likes()->where($userCheck)->exists()) {
- $this->likes()->create($userCheck);
- }
- }
- public function isLiked() {
- return $this->likes()->where('user_id', auth()->id())->exists();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement