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
-
Declare that model implements
Cog\Contracts\Love\Reactable\Models\Reactable
contract. -
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\Models;
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
- Run set up reactable command.
$ php artisan love:setup-reactable --model="App\Models\Comment" --nullable
Remove
--nullable
flag if all models of this type must be reactable:$ php artisan love:setup-reactable --model="App\Models\Comment"
Manual migration creation described in Custom Setup Migrations.
- 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\Models\Comment"
This command will create Reactant model for each Comment model.
Updated almost 2 years ago