Skip to content

Verifiable model

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

Setup a verifiable model

With boolean flag

<?php

namespace App\Models;

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

class Post extends Model
{
    use HasVerifiedFlag;
}

Model must have boolean is_verified column in database table.

With timestamp flag

<?php

namespace App\Models;

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

class Post extends Model
{
    use HasVerifiedAt;
}

Model must have nullable timestamp verified_at column in database table.

Available functions

Get verified + not verified models

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

Get only verified models

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

Get only not verified models

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

Verify model

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

Undo model verify

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