本文介紹了Laravel 5 如何獲取路由操作名稱?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試獲取當前的路線操作,但我不確定如何去做.在 Laravel 4 中,我使用了 Route::currentRouteAction()
但現在有點不同.
I'm trying to get the current route action, but I'm not sure how to go about it. In Laravel 4 I was using Route::currentRouteAction()
but now it's a bit different.
我正在嘗試在我的控制器中執行 Route::getActionName()
但它一直給我找不到方法.
I'm trying to do Route::getActionName()
in my controller but it keeps giving me method not found.
<?php namespace AppHttpControllers;
use Route;
class HomeController extends Controller
{
public function getIndex()
{
echo 'getIndex';
echo Route::getActionName();
}
}
推薦答案
在 Laravel 5 中,您應該使用方法或構造函數注入.這將執行您想要的操作:
In Laravel 5 you should be using Method or Constructor injection. This will do what you want:
<?php namespace AppHttpControllers;
use IlluminateRoutingRoute;
class HomeController extends Controller
{
public function getIndex(Route $route)
{
echo 'getIndex';
echo $route->getActionName();
}
}
這篇關于Laravel 5 如何獲取路由操作名稱?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!