1.直接写绝对路径,这样会用在/goods/show前面加上域名

<a href="/goods/show?id=<?php echo $item['id']; ?>">这是一个跳转</a>

2.分析使用route和url辅助函数

2.1route()配合路由中的别名来使用

route 函数生成指定路由名称网址:

Route::get('user/profile', ['as' => 'profile', function ($id) { // }])

$url = route('profile');

如果该路由接受参数,你可以作为第二参数传递:

Route::get('user/{id}/profile', ['as' => 'profile', function ($id) { // }]); $url = route('profile', ['id' => 1]);

这样的好处是当我们修改user/profile时候不用去我们工程的所有地方修改url跳转

2.2url()

url 函数生成指定路径的完整网址:

function url($path = null, $parameters = [], $secure = null)

url()方法生成一个完整的网址。

Route::get('user/profile', ['as' => 'profile', function ($id) { // }])

echo url('user/profile');

3.进一步分析

创建路由如下所示:

Route::get('articles',['uses'=>'ArticlesController@index','as'=>'articles.index']);

要访问该URL可以通过如下形式:

//URL方式

<a href="{{ url('/articles') }}">

//Route方式

<a href="{{ URL::route('articles.index') }}">

//Action方式

<a href="{{ URL::action('ArticlesController@index') }}">

所以在路由配置中,每个参数的代表意义为:以下粗体部分别人对应url,action,router

Route::get('articles',['users'=>ArticelsController@index','as'=>'articles.index']);

4.asset()的用法

function asset($path, $secure = null)

asset()方法用于引入 CSS/JavaScript/images 等文件,文件必须存放在public文件目录下。

这样比直接引用的好处是,可以节省资源,压缩文件