6

I'm trying to access the name of the current controller and the current method to pass it to my view as a variable. I've tried several ways from pointers I found online but they don't work so I assume they were for Laravel 3.

Here is what I've tried

Request::$route->controller

gives

Access to undeclared static property: Illuminate\Support\Facades\Request::$route

and

Request::route()->controller

gives

Call to undefined method Illuminate\Http\Request::route()
4

5 に答える 5

10
Route::currentRouteAction()

例: "RecordAPIController@show" を返します

于 2014-09-10T22:55:08.027 に答える
7

ルート ドキュメントに従ってルートに名前を付けてから、$name = Route::currentRouteName();

どのコントローラー/ルートが事前に起動されているかわからないのは、どのような状態ですか? ユースケースを教えてください。

于 2013-07-21T03:04:17.353 に答える
1

Laravel used "Request" as alias for 'Illuminate\Support\Facades\Request' (can be found in app.php). My advices is to avoid using "Request" as your model/controller/view name.

于 2015-05-27T15:33:29.093 に答える
-3

Laravel ではなく、基本的な php 定数/関数を使用できます。

__LINE__, __FILE__, __FUNCTION__, __CLASS__, __METHOD__

現在の行、ファイル、関数、クラス、またはメソッドを提供します

get_class()

あなたに現在のクラスを与える

于 2014-03-06T10:05:37.753 に答える