*/protectedfunctionloadRoutes(){// 加载应用的路由通过执行服务容器的 call 方法调用相关加载类// 这里既是调用子类 App\\Providers\\RouteServiceProvider::class 的 map 方法读取配置。if(method_exists($this,'map')){$this->app->call([$this,'map']);}}} 「路由服务提供者」启动过程总结起来一共分为...
Route::pattern('id','[0-9]+'); Route::get('user/{id}',function($id) { // Only called if {id} is numeric. }); 访问路由参数 如果想在路由范围外访问路由参数,可以使用Route::input方法: Route::filter('foo',function() { if(Route::input('id')==1) ...
Route::get('user/profile', array('as' => 'profile', 'uses' => 'UserController@showProfile')); 现在,你可以使用路由名称来创建URL和重定向: 代码如下: $url = URL::route('profile'); $redirect = Redirect::route('profile'); 可以使用currentRouteName方法来获取当前运行的路由名称: 代码如下: $...
1Route::get('/user/{id}', function ($id) { 2 // Only executed if {id} is numeric... 3});Encoded Forward SlashesThe Laravel routing component allows all characters except / to be present within route parameter values. You must explicitly allow / to be part of your placeholder using ...
1Route::permanentRedirect('/here', '/there');When using route parameters in redirect routes, the following parameters are reserved by Laravel and cannot be used: destination and status.View RoutesIf your route only needs to return a view, you may use the Route::view method. Like the ...
// \Illuminate\Session\Middleware\StartSession protected function storeCurrentUrl(Request $request, $session) { // 如果是GET,并且不是ajax,且route对象不能为空 if ($request->method() === 'GET' && $request->route() && ! $request->ajax()) { $session->setPreviousUrl($request->fullUrl()...
一,报错信息 post到不存在的路由时,会触发MethodNotAllowedHttpException,提示信息: The POST method is not supported for route login/login. Supported methods: GET, HEAD."
if (count($others) > 0) { return $this->getRouteForMethods($request, $others); } throw new NotFoundHttpException; 这里的逻辑是: 1. 首先根据当前HTTP方法(GET/POST/PUT/...)查找是否有匹配的路由,如果有(if(! is_null($route))条件成立),非常好,绑定后直接返回,继续此后的调用流程即可; ...
public function onOpen(Server $server, Request $request) { // Before the onOpen event is triggered, the HTTP request to establish the WebSocket has passed the Laravel route, // so Laravel's Request, Auth information are readable, Session is readable and writable, but only in the onOpen ev...
Route::get('user/{id}', function($id) { // Only called if {id} is numeric. }); 访问路由参数 如果想在路由范围外访问路由参数,可以使用 Route::input 方法: 代码如下: Route::filter('foo', function() { if (Route::input('id') == 1) ...