Elequent relationship query
I have Item that hasMany statuses ..
I want to create a method inside the item model to know if it has a status 'Review' or not
I came up with this but no hope.
public function scopeReviewed($query)
{
return $this->whereHas('statuses',function(Builder $query){
$query->where('status','Review');
})->count() > 0;
}
any help?
You can use getAttribute laravel magic function in your model :
public function getIsScopeReviewedAttribute()
{
return $this->whereHas('statuses', function($query){
$query->where('status', 'Review');
})->exists();
}
Then you can call it like this :
$model->is_scope_reviewed;
Please or to participate in this conversation.