Skip to content

Verifiable model

Pe Ell edited this page Apr 17, 2017 · 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 only verified models

Post::all();
Post::withoutUnverified();

Get only unverified models

Post::onlyUnverified();

Get verified + unverified models

Post::withUnverified();

Verify model

Post::where('id', 4)->verify();

Unverify model

Post::where('id', 4)->unverify();