jobmetric / laravel-star

This is a star rating management package for any object in Laravel that you can use in your projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Contributors Forks Stargazers MIT License LinkedIn

Star for laravel

This is a star rating management package for any object in Laravel that you can use in your projects.

Install via composer

Run the following command to pull in the latest version:

composer require jobmetric/laravel-star

Documentation

This package evolves every day under continuous development and integrates a diverse set of features. It's a must-have asset for Laravel enthusiasts and provides a seamless way to align your projects with basic star and rating models.

In this package, you can use it seamlessly with any model that needs stars and ratings.

Now let's go to the main function.

Before doing anything, you must migrate after installing the package by composer.

php artisan migrate

Meet the HasStar class, meticulously designed for integration into your model. This class automates essential tasks, ensuring a streamlined process for:

In the first step, you need to connect this class to your main model.

use JobMetric\Like\HasStar;

class Post extends Model
{
    use HasStar;
}

How is it used?

You can now use the HasStar class for your model. The following example shows how to create a new post with ratings and stars:

$post = Post::create([
    'status' => 'published',
]);

$user_id = 1;

$post->starIt($user_id, $star = 5);

The starIt function is used to rate the post. The first parameter is the user id, and the second parameter is the star rating.

Now we go to the functions that we have added to our model.

starTo

star has one relationship

starsTo

star has many relationships

starCount

get star count

starAvg

get star average

withStarCount

load star count after a model loaded

$post->withStarCount();

withStarAvg

load star avg after a model loaded

withStar

load star or disStar after model loaded

withStars

load stars after models loaded

isStaredStatusBy

is stared by user

$user_id = 1;

$post->isStaredStatusBy($user_id);

forgetStar

forget star

$user_id = 1;

$post->forgetStar($user_id);

forgetStars

forget stars

$post->forgetStars();

Contributing

Thank you for considering contributing to the Laravel Star! The contribution guide can be found in the CONTRIBUTING.md.

License

The MIT License (MIT). Please see License File for more information.

About

This is a star rating management package for any object in Laravel that you can use in your projects.

License:MIT License


Languages

Language:PHP 100.0%