Route model Binding

I have different models, where I have a published_at date as a field and I have different routes, where I use these models with route bindings.

On the front end, I only want to show "published" models (aka published_at > now()). This is easily done by adding the following to the models:

public function resolveRouteBindingQuery($query, $value, $field = null)
{
    return parent::resolveRouteBindingQuery($query, $value, $field)->where("published_at", ">", now());
}


The problem is, that this logic obviously also kicks in in admin panel, so I get a 404 on "unpublished" resources.

Any elegent solutions for this? For example, can I exclude somehow the admin from my resolveRouteBindingQuery logic?
Was this page helpful?