Setup Reacterable
User
model cannot directly react to the content. It should delegate this job to related Reacter
model.
Code Changes
-
Declare that model implements
Cog\Contracts\Love\Reacterable\Models\Reacterable
contract. -
Use
Cog\Laravel\Love\Reacterable\Models\Traits\Reacterable
trait or implement each method of the contract by yourself.
As result you will have:
<?php
namespace App\Models;
use Cog\Contracts\Love\Reacterable\Models\Reacterable as ReacterableInterface;
use Cog\Laravel\Love\Reacterable\Models\Traits\Reacterable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable implements ReacterableInterface
{
use Reacterable;
}
Database Changes
- Run set up reacterable command.
php artisan love:setup-reacterable --model="App\Models\User"
Add
--nullable
flag if all models of this type must NOT be reacterable:$ php artisan love:setup-reacterable --model="App\Models\User" --nullable
Manual migration creation described in Custom Setup Migrations.
- Run migration.
php artisan migrate
Creating Reacter Models
If you are integrating package on already existing user base you need to register your Reacterable models as Reacters.
php artisan love:register-reacters --model="App\Models\User"
This command will create Reacter model for each User model.
Adding query scopes to Model
Note
This step is optional. Required only for Reacterable Filtering functionality.
This package comes with predefined query builder methods to use database query scopes.
To start using it in your User model you should create UserQueryBuilder
class.
<?php
namespace App\Models;
class UserEloquentBuilder extends \Illuminate\Database\Eloquent\Builder
{
use \Cog\Laravel\Love\Reacterable\ReacterableEloquentBuilderTrait;
// Other User model local query scopes
}
Then in your User
model register that it should be used instead of the default \Illuminate\Database\Eloquent\Builder
class.
<?php
namespace App\Models;
use Cog\Contracts\Love\Reacterable\Models\Reacterable as ReacterableInterface;
use Cog\Laravel\Love\Reacterable\Models\Traits\Reacterable;
use Illuminate\Foundation\Auth\User as Authenticatable;
/**
* @method static UserEloquentBuilder query()
*/
class User extends Authenticatable implements ReacterableInterface
{
use Reacterable;
public function newEloquentBuilder($query): UserEloquentBuilder
{
return new UserEloquentBuilder($query);
}
}
Updated 10 months ago