Laravel中route生成url函数解析

/**
     * Generate the URL to a named route.
     *
     * @param  array|string  $name
     * @param  mixed  $parameters
     * @param  bool  $absolute
     * @return string
     */
    function route($name, $parameters = [], $absolute = true)
    {
        return app('url')->route($name, $parameters, $absolute);
    }

通过route函数可以通过路由生成指定路由的url地址,3个参数解释如下:

1.$name  路由的名字,在api.php 或 web.php 中

2.$parameters 绑定参数,例如:

$url = route('baidu', ['name' => 'zhangsan']);

3.$absolute 生成绝对地址还是相对地址,默认true 生成绝对地址。实际开发中需要哪种地址,通过设置这个参数就可以了。

生成绝对地址:"https://www.baidu.com/name/zhangsan"

$url = route('baidu', ['name' => 'zhangsan']);

生成相对地址: "/name/zhangsan"

$url = route('baidu', ['name' => 'zhangsan']);
原文地址:https://www.cnblogs.com/wjs2019/p/15192424.html