![](/img/trans.png)
[英]Get all the Controller & resources from the routes.php in Laravel 5.2
[英]get prefix value from below array at routes.php in laravel
Route::group(['prefix' => 'admin','middleware' => 'auth'], function($router) {
dd($router);
include('moduleroutes.php');
});
我在route.php中得到了轟鳴聲數組。 我如何從這個數組中獲取前綴值。
Router {#24 ▼
#events: Dispatcher {#5 ▶}
#container: Application {#2 ▶}
#routes: RouteCollection {#26 ▶}
#current: null
#currentRequest: null
#middleware: array:7 [▶]
#middlewareGroups: array:2 [▶]
#binders: array:1 [▶]
#patterns: []
#groupStack: array:2 [▼
0 => array:2 [▶]
1 => array:4 [▼
"middleware" => array:2 [▶]
"prefix" => "/admin" //want value "admin"
"namespace" => "App\Http\Controllers"
"where" => []
]
]
}
請指導我。 謝謝。
在控制器內部,您可以使用它來獲取前綴:
echo $this->getRouter()->getCurrentRoute()->getPrefix();
更新
如果你想在組中獲得前綴,你可以這樣做:
$adminPrefix = 'admin'; // Alternatively you could keep this variable in config file.
Route::group(['prefix' => $adminPrefix, 'middleware' => 'auth'], function($router) use ($adminPrefix) {
echo $adminPrefix;
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.