User clap/unclap behaviour for Laravel.
3.3.0
2024-03-18 14:48 UTC
Requires
- php: ^8.0
- illuminate/database: ^8.13 || ^9.0 || ^10.0 || ^11.0
- illuminate/support: ^8.0 || ^9.0 || ^10.0 || ^11.0
- laravel-interaction/support: ^1.0 || ^2.0 || ^3.0
Requires (Dev)
- mockery/mockery: ~1.3.3 || ^1.4.2
- orchestra/testbench: ^6.0 || ^7.0 || ^8.0 || ^9.0
- phpunit/phpunit: ^9.3.3 || ^10.0
This package is auto-updated.
Last update: 2024-11-13 13:11:44 UTC
README
User clap/unclap behaviour for Laravel.
Introduction
It let people express how they feel about the model(documentation/subject/topic).
Installation
Requirements
Instructions
Require Laravel Clap using Composer.
composer require laravel-interaction/clap
Publish configuration and migrations
php artisan vendor:publish --tag=clap-config php artisan vendor:publish --tag=clap-migrations
Run database migrations.
php artisan migrate
Usage
Setup Clapper
use Illuminate\Database\Eloquent\Model; use LaravelInteraction\Clap\Concerns\Clapper; class User extends Model { use Clapper; }
Setup Ratable
use Illuminate\Database\Eloquent\Model; use LaravelInteraction\Clap\Concerns\Clappable; class Channel extends Model { use Clappable; }
Clapr
use LaravelInteraction\Clap\Tests\Models\Channel; /** @var \LaravelInteraction\Clap\Tests\Models\User $user */ /** @var \LaravelInteraction\Clap\Tests\Models\Channel $channel */ // Clap to Ratable $user->clap($channel); // clap is only allowed to be called once $user->clapOnce($channel); $user->unclap($channel); // Compare Ratable $user->hasClapped($channel); $user->hasNotClapped($channel); // Get clapped info $user->clapperApplause()->count(); // with type $user->clapperApplause()->withType(Channel::class)->count(); // get clapped channels Channel::query()->whereClappedBy($user)->get(); // get channels doesnt clapped by user Channel::query()->whereNotClappedBy($user)->get();
Ratable
use LaravelInteraction\Clap\Tests\Models\User; use LaravelInteraction\Clap\Tests\Models\Channel; /** @var \LaravelInteraction\Clap\Tests\Models\User $user */ /** @var \LaravelInteraction\Clap\Tests\Models\Channel $channel */ // Compare Clapper $channel->isClappedBy($user); $channel->isNotClappedBy($user); // Get clappers info $channel->clappers->each(function (User $user){ echo $user->getKey(); }); $channel->loadClappersCount(); $channels = Channel::query()->withClappersCount()->get(); $channels->each(function (Channel $channel){ echo $channel->clappers()->count(); // 1100 echo $channel->clappers_count; // "1100" echo $channel->clappersCount(); // 1100 echo $channel->clappersCountForHumans(); // "1.1K" });
Events
License
Laravel Clap is an open-sourced software licensed under the MIT license.