Setup Reactable

Comment model cannot receive reactions directly. It should delegate this job to related Reactant model.

Add Reactable interface & trait to your Comment model code and run artisan setup command to make a link with Reactant model.

Code Changes

  1. Declare that model implements Cog\Contracts\Love\Reactable\Models\Reactable contract.

  2. Use Cog\Laravel\Love\Reactable\Models\Traits\Reactable trait or implement each method of the contract by yourself.

As result you will have:

<?php

namespace App;

use Cog\Contracts\Love\Reactable\Models\Reactable as ReactableInterface;
use Cog\Laravel\Love\Reactable\Models\Traits\Reactable;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model implements ReactableInterface
{
    use Reactable;
}

Database Changes

  1. Run set up reactable command.
$ php artisan love:setup-reactable --model="App\Comment" --nullable

📘

Remove --nullable flag if all models of this type must be reactable:

$ php artisan love:setup-reactable --model="App\Comment"

📘

Manual migration creation described in Custom Setup Migrations.

  1. Run migration.
$ php artisan migrate

Creating Reactant Models

If you are integrating package on already existing user base you need to register your Reactable models as Reactants.

$ php artisan love:register-reactants --model="App\Comment"

This command will create Reactant model for each Comment model.