2017-07-21 20 views
0

我試圖通過使用路徑來訪問HTML鏈接內的3個變量值的命名與此代碼路由:Laravel傳遞變量訪問一個名爲路線

<a href="{{ route('gegonota', ['gid' => $gid,'cid' => $cid , 'nid' => $nid]) }}">{{$nomos->name}}</a> 

也路由功能是

Route::get('gegonota/{gid?}/{cid?}/{nid?}', ['uses' => '[email protected]', 'as' => 'gegonota']); 

但它不工作的權利。 我該怎麼做。 謝謝

+0

顯示錯誤你正在得到 –

回答

0

你可以試試這個。

<a href="{{ route('gegonota', [ $gid,$cid , $nid]) }}">{{$nomos->name}}</a> 
+0

非常感謝這是很大的幫助,但現在有另一個問題,當我傳遞一個null變量(與空值)它給了我錯誤(1/1)NotFoundHttpException。 例如其中一個變量爲null,因爲它應該是路由中定義的可選路由(Route :: get('gegonota/{gid?}/{cid?}),但是我稱之爲路由gegonota/1 // 0第二個是null給出了我提到的錯誤 –

0

剛剛從你的路由刪除? PARAMS所以這將是:

Route::get('gegonota/{gid}/{cid}/{nid}', [ 
'uses' => '[email protected]', 
'as' => 'gegonota' 
]); 

,如果你想使用?您需要提供一個默認值檢查docs

,如果你使用Laravel v5.4您需要將您的路線改爲:

Route::get('gegonota/{gid}/{cid}/{nid}', [ 
    'uses' => '[email protected]' 
])->name('gegonota'); 
+0

我試圖在路由中的可選變量中給出null值,但是給出了錯誤代碼是 Route :: get('gegonota/{gid?}/{cid?}/{nid '''','function'($ gid = null,$ cid = null,$ nid = null){ return $ gid $ cid $ nid; }, ['uses'=>'GegonosController @ index','as' =>'gegonota']); –

+0

你得到了什麼錯誤? –

+0

我改變了那個 Route :: get('gegonota/{gid?}/{cid?}/{nid?}',function($ gid = null,$ cid = null,$ nid = null){ return $ gid,$ cid,$ nid; },['uses'=>'G egonosController @索引 ']) - >名稱(' gegonota'); 並給我的錯誤語法錯誤,意外的',' –