Skip to main content
Quick Tip

Override the route binding resolver for each of your models

You can override the route binding resolver for each of your models. In this example, I have no control over the @ sign in the URL, so using the resolveRouteBinding method, I'm able to remove the @ sign and resolve the model.

// Route
Route::get('{product:slug}', Controller::class);
 
// Request
https://nodejs.pub/@unlock/hello-world
 
// Product Model
public function resolveRouteBinding($value, $field = null)
{
$value = str_replace('@', '', $value);
 
return parent::resolveRouteBinding($value, $field);
}

Tip given by @Philo01

Enjoyed This Tip?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Recent Courses

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.