Run database migrations for Laravel Love
masterAfter installing the package, you must run the database migrations to set up the necessary tables for reactions and votes.
$ php artisan migraterepository·master·Indexed 22 days ago
https://github.com/cybercog/laravel-loveA Laravel package that enables emotional reactions (similar to GitHub, Facebook, or YouTube) for any Eloquent model. It provides tools for managing reaction types, registering reactable and reacterable models, and rebuilding reaction aggregates via Artisan commands. The package includes comprehensive migration paths for upgrading between versions v5 through v10.
After installing the package, you must run the database migrations to set up the necessary tables for reactions and votes.
$ php artisan migrateIn v9, Reactable trait methods like scopeWhereReactedBy, scopeWhereNotReactedBy, scopeJoinReactionCounterOfType, and scopeJoinReactionTotal were moved to ReactableEloquentBuilderTrait.
To continue using these scopes, you must create a custom Eloquent Builder class, use the trait within it, and override the newEloquentBuilder method in your model.
/**
* @method static UserEloquentBuilder query()
*/
class User extends Model
{
public function newEloquentBuilder($query): UserEloquentBuilder
{
return new UserEloquentBuilder($query);
}
}
class UserEloquentBuilder extends \Illuminate\Database\Eloquent\Builder
{
use \Cog\Laravel\Love\Reactable\ReactableEloquentBuilderTrait;
// Other User model local query scopes
}Upgrading from v7 to v8 involves several breaking changes to method names and data types:
weight values are now float. Round them manually if you require integer values.isReactedTo and isReactedToWithType with hasReactedTo.isNotReactedTo and isNotReactedToWithType with hasNotReactedTo.isReactedByWithType with isReactedBy.isNotReactedByWithType with isNotReactedBy.ReactionType::getWeight() is renamed to getMass().whereReactedByWithType with whereReactedBy.whereReactedBy now expects the first argument to be the Reacterable and the second to be the string name of the ReactionType.joinReactionCounterOfType now expects the ReactionType as a string name.joinReactionCounterOfType prefix changed from reactions_ to reaction_{$type}_.joinReactionTotal prefix changed from reactions_total to reaction_total_.IMPORTANT: Create a backup of your production database before proceeding.
Run the automated migration command (requires doctrine/dbal):
php artisan love:upgrade-v7-to-v8php artisan love:upgrade-v7-to-v8If you are using the Love facade, you must switch to the new specialized facades. The global Cog\Laravel\Love\Facades\Love facade has been removed.
New Facades:
Cog\Laravel\Love\Reacter\Facades\ReacterCog\Laravel\Love\Reactant\Facades\ReactantContract Implementation:
If you implement Reactable or Reacterable contracts manually (without using packaged traits), you must implement these two new methods:
Reactable models must implement viaLoveReactant.Reacterable models must implement viaLoveReacter.When upgrading to v10, note the following breaking changes:
ReactionCounterObserver, ReactionTotalObserver, and the ReactionObserver::creating event have been removed.ReactionCounter, ReactionTotal, and Reaction models are now defined directly inside the models. If you use the package's default models, this is not a breaking change.To add Laravel Love to your project, pull in the package using Composer.
$ composer require cybercog/laravel-loveThe love:recount command no longer uses the sync connection by default; it now uses the value defined in your queue.default configuration.
To force a synchronous statistics recount, use the --queue-connection=sync option.
php artisan love:recount --model="App\User" --queue-connection=syncv6 is a major refactor. Most changes cannot be automated due to API differences.
Cog\Contracts\Love\Likeable\Models\Likeable $\rightarrow$ Cog\Contracts\Love\Reactable\Models\ReactableCog\Laravel\Love\Likeable\Models\Traits\Likeable $\rightarrow$ Cog\Laravel\Love\Reactable\Models\Traits\ReactableCog\Contracts\Love\Liker\Models\Liker $\rightarrow$ Cog\Contracts\Love\Reacterable\Models\ReacterableCog\Laravel\Love\Liker\Models\Traits\Liker $\rightarrow$ Cog\Laravel\Love\Reacterable\Models\Traits\ReacterableAdd the following columns to every table that models can react on/to:
$table->unsignedBigInteger('love_reacter_id'); (for models that can react)$table->unsignedBigInteger('love_reactant_id'); (for models that can be reacted upon)whereLikedBy / whereDislikedBy $\rightarrow$ whereReactedByWithTypelike / dislike $\rightarrow$ reactTounlike / undislike $\rightarrow$ unreactToorderByLikesCount / orderByDislikesCount $\rightarrow$ use joinReactionCounterOfType combined with a standard orderBy.IMPORTANT: Create a backup of your production database before proceeding.
Run the automated migration command:
php artisan love:upgrade-v5-to-v6php artisan love:upgrade-v5-to-v6UPGRADING.md file in the repository.When upgrading the Laravel Love package from version 5 to version 6, use the love:upgrade-v5-to-v6 Artisan command. This command automates the migration of your database schema and data from the old 'likes' system to the new 'reactions' system.
The command performs the following steps:
ReactionType records.Reacter records for your user models (based on your default auth guard).Reactant records for your models that were previously likeable.love_likes table into the new reactions table.love_likes, love_like_counters) and removes obsolete migration files.The love:setup-reacterable command supports the following options:
--model: The fully qualified class name of the model you want to make reacterable (e.g., App\Models\Post). If omitted, you will be prompted to enter the name.--not-nullable: If this flag is present, the generated migration will create the love_reacter_id foreign column as NOT NULL. If the flag is absent, the column will be nullable.The love:register-reactants command accepts the following options:
--model: Required. The fully qualified class name of the Reactable model (e.g., App\Models\Post). If you use a morph map, you can provide the morph map alias instead.--ids: Optional. A comma-separated list of specific model IDs to register (e.g., --ids=1,2,16,34). If this option is omitted, the command will attempt to register all unregistered models of the specified type.