Models Registration

There are many cases when developer need to have more control over models registration process:

  • only subscribed users can react;
  • only featured articles could be reacted.

Add special methods with control logic to application models.

Reacterable Registration Control

Each Reacterable model on create automatically registers as Reacter.

Add boolean method shouldRegisterAsLoveReacterOnCreate to Reacterable model and return false value in cases where default scenario should be skipped.

<?php

namespace App;

use Cog\Contracts\Love\Reacterable\Models\Reacterable as ReacterableContract;
use Cog\Laravel\Love\Reacterable\Models\Traits\Reacterable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements ReacterableContract
{
    use Reacterable;

    public function shouldRegisterAsLoveReacterOnCreate(): bool
    {
        // Pseudo-code which checks if user is subscribed
        return $this->isSubscribed();
    }
}

Reactable Registration Control

Each Reactable model on create automatically registers as Reactant.

Add boolean method shouldRegisterAsLoveReactantOnCreate to Reactable model and return false value in cases where default scenario should be skipped.

<?php

namespace App;

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

class Article extends Model implements ReactableContract
{
    use Reactable;

    public function shouldRegisterAsLoveReactantOnCreate(): bool
    {
        // Pseudo-code which checks if article is featured
        return $this->isFeatured();
    }
}