Skip to content

A trait (for OctoberCMS) that makes it possible to "like" other models.

License

Notifications You must be signed in to change notification settings

Rebel59/oc-likeable-trait

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Likeable Trait

A trait (for OctoberCMS) that makes it possible to "like" other models.

This repo is currently in active development / unfinished

This trait has been made for an ongoing project. Usage therefore isn't advised until it is finished.

How to use

Add the trait to the model as you would like with any other trait.

use Rebel59\Likeable\Traits\Likeable;

class Post extends Model 
{
    use Likeable;
    
    
}

The trait depens on a morphed relation, so populate the $morphMany field.

use Rebel59\Likeable\Traits\Likeable;
use Rebel59\Likeable\Models\Like;

class Post extends Model 
{
    use Likeable;
    
    public $morphMany = [
        'likes' => [Like::class, 'name' => 'likeable']
    ]
}

Currently the Likeable trait adds the following (working) functionality.

like($userId) - Adds a new like to the model from specified user (id).

$model->like($user->id);

unlike($userId) - Removes a like from the model belonging to the specified user (id).

$model->like($user->id);

scopeWhereLikedBy($query, $userId) - Find records that are liked by the specified user (id)

$model->whereLikedBy($user->id);

liked($userId=null) - Check if the currently logged in user / specified user, has liked the record.

$model->liked; // gets currently logged in user and checks if that user had liked the record
$model->liked($userId) //checks if the specified user has liked the record.

License

All this is licensed under the MIT licenes.

About

A trait (for OctoberCMS) that makes it possible to "like" other models.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages