Pharaonic
Loading...

# User Model

This is the primary way that you can use to create a new like to the model through User Model.

# Inclusion

You have to include the isLiker trait into the User Model.

1namespace App\Models;
2 
3use Illuminate\Foundation\Auth\User as Authenticatable;
4use Pharaonic\Laravel\Users\Traits\Actions\Like\isLiker;
5 
6class User extends Authenticatable
7{
8 use isLiker;
9 
10 protected $fillable = ['name', 'email', 'password'];
11}

# like

This is how you can create a new like to the $post model through User model.

1$user->like($post);
2// Returns Boolean

# unlike

This is how you can unlike the $post model through User model.

1$user->unlike($post);
2// Returns Boolean

# liked

This is how you can check the $post model that has been liked by User model.

1if($user->liked($post)) {
2 //
3}

# Likeable Model

This is the secondary way that you can use to create a new like to the model.

# Inclusion

You have to include the isLikeable trait into the Model.

1namespace App\Models;
2 
3use Illuminate\Database\Eloquent\Model;
4use Pharaonic\Laravel\Users\Traits\Actions\Like\isLikeable;
5 
6class Post extends Model
7{
8 use isLikeable;
9 
10 protected $fillable = ['content', 'user_id'];
11}

# likeBy

This is how you can create a new like to the $post model.

1$post->likeBy($user);
2// Returns Boolean

# unlikeBy

This is how you can unlike the $post model.

1$post->unlikeBy($user);
2// Returns Boolean

# likedBy

This is how you can check the $post model that has been liked.

1if($post->likedBy($user)) {
2 //
3}

# Relationships

  • likes
    • liker
    • likeable