Skip to content

Instantly share code, notes, and snippets.

@huzaifa-a
Last active January 15, 2021 09:24
Show Gist options
  • Save huzaifa-a/57ca85c14f7bf23357c06ecffb347296 to your computer and use it in GitHub Desktop.
Save huzaifa-a/57ca85c14f7bf23357c06ecffb347296 to your computer and use it in GitHub Desktop.
Resolve model binding

add in model

public function resolveRouteBinding($value, $field = null)
{
    if (auth()->check()){
        if (!Auth::user()->is_admin()) {
            return $this->where('user_id', Auth::id())->where($field ?? $this->getRouteKeyName(), $value)->first();
        }
    }

    return $this->where($field ?? $this->getRouteKeyName(), $value)->first();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment