I just read the Laravel news post about the Url::defaults method.
The article doesn't mention it has a caveat, that can cause a model binding problem.
Why would you use global middleware to make it easier to get a route in blade in the first place?
A less invasive way to solve this is to create a helper.
function localeRoute($name, $parameters = [], $absolute = true) { foreach (['locale' => 'en'] as $key => $value) { if(array_key_exists($key, $parameters)) { continue; } $parameters[$key] = $value; } return app('url')->route($name, $parameters, $absolute); }
And use it in views where it makes sense.
The above is the detailed content of My thoughts on the Url::defaults method. For more information, please follow other related articles on the PHP Chinese website!