Extracting scope status with Eloquent

Uniform the status scoping and do better setting.

In project, your posts, articles and others, the status are uniform for initial design, but you distributed on each model like this:

// Post.php
public function scopeStatus($query, $status)
{
return $query->where('status', $status);
}
public function scopePrivate($query)
{
return $query->status(static::$private);
}
public function scopePublic($query)
{
return $query->status(static::$public);
}
public function scopeProtected($query)
{
return $query->status(static::$protected);
}

and each model owns it, it’s wired, so how’s best practice?
you can put in App\Eloquent\Concerns\HasStatus

namespace App\Eloquent\Concerns;
trait HasStatus
{
public static $private = 0;
public static $public = 1;
public static $protected = 2;
public function scopeStatus($query, $status)
{
return $query->where('status', $status);
}
public function scopePrivate($query)
{
return $query->status(static::$private);
}
public function scopePublic($query)
{
return $query->status(static::$public);
}
public function scopeProtected($query)
{
return $query->status(static::$protected);
}
}

Next, if you need to use it, you can use the trait to specific eloquent:
Notice: if you need to set readable and extendable, you can do contract.

//App\Eloquent\Contracts\Statusable.php
interface Statusable
{
public function scopeStatus($query, $status);
}

Finally, implement and use trait.

class Post extends Model implements Statusable
{
use HasStatus,