Home > Backend Development > PHP Tutorial > My thoughts on the Url::defaults method

My thoughts on the Url::defaults method

Patricia Arquette
Release: 2024-12-20 21:00:13
Original
225 people have browsed it

My thoughts on the Url::defaults method

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);
}
Copy after login

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!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template