Skip to content

Acceptable model

Anton Komarev edited this page Mar 24, 2020 · 5 revisions

Setup an acceptable model

With boolean flag

<?php

namespace App\Models;

use Cog\Flag\Traits\Classic\HasAcceptedFlag;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasAcceptedFlag;
}

Model must have boolean is_accepted column in database table.

With timestamp flag

<?php

namespace App\Models;

use Cog\Flag\Traits\Classic\HasAcceptedAt;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasAcceptedAt;
}

Model must have nullable timestamp accepted_at column in database table.

Available functions

Get accepted + not accepted models

Post::all();
Post::withNotAccepted()->get();

Get only accepted models

Post::withoutNotAccepted()->get();

Get only not accepted models

Post::onlyNotAccepted()->get();

Accept model

Post::whereKey(4)->accept();

Undo model accept

Post::whereKey(4)->undoAccept();