Route::getCurrentRoute()->getPath();因为Route对象属于请求阶段,而框架将其关联到了 Request 对象上,所以也可以下面这样链式调用:Request::route()->getName();在 Laravel 5.1 内这样写:useIlluminate\Support\Facades\Route;$currentPath= Route::getFacadeRoot()->current()->uri();Laravel 5.2 使用...
Route::getCurrentRoute()->getPath(); 因为Route对象属于请求阶段,而框架将其关联到了 Request 对象上,所以也可以下面这样链式调用: Request::route()->getName(); 在Laravel 5.1 内这样写: use Illuminate\Support\Facades\Route;$currentPath= Route::getFacadeRoot()->current()->uri(); Laravel 5.2 使用...
Route::getCurrentRoute()->getPath(); 因为Route对象属于请求阶段,而框架将其关联到了 Request 对象上,所以也可以下面这样链式调用: Request::route()->getName(); 在Laravel 5.1 内这样写: use Illuminate\Support\Facades\Route; $currentPath= Route::getFacadeRoot()->current()->uri(); Laravel 5....
Route::get('user/profile', array('as' => 'profile', 'uses' => 'UserController@showProfile')); 现在您在生成 URLs 或跳转的时候使用路由的名字: 代码如下: $url = URL::route('profile'); $redirect = Redirect::route('profile'); 您可以使用 currentRouteName 方法获取一个路由的名字: 代码如下...
通过Route::current()访问当前的路由 $route= Route::current();$name=$route->getName();$actionName=$route->getActionName(); $name= Route::currentRouteName();$action= Route::currentRouteAction(); 二 路由参数 必选参数 Route::get('user/{id}',function($id) {return'User '.$id; ...
Route::get('user/{id}/{name}',function($id,$name) { // }) ->where(array('id'=>'[0-9]+','name'=>'[a-z]+')) 定义全局模式 如果希望在全局范围用指定正则表达式限定路由参数,可以使用pattern方法: Route::pattern('id','[0-9]+'); ...
Route::get('/locations/{location:slug}', [LocationsController::class,'show']) ->name('locations.view') ->missing(function(Request$request){returnRedirect::route('locations.index'); }); 显示绑定 我们不需要使用Laravel的基于约定的隐式模型解析来使用模型绑定。 我们还可以显式定义路由的参数与模型对...
$route = pathinfo($request->decodedPath(), PATHINFO_FILENAME); $name = Route::currentRouteName(); 1. 2. 使用URL类: // 返回当前页面的地址:http:///platforms URL::full(); url()->full(); // 返回当前页面的完整路径:http:///platforms ...
$name = Route::currentRouteName(); 6.路由群组 有时候许多路由会有公用的需求,例如 URL 区段、中间件、命名空间等等。 利用路由群组套用这些属性到多个路由,而不用每个路由都设置一次。 6.1中间件 MiddleWare 在群组共享属性数组的 middleware 参数定义中间件列表,这些中间件就会应用到群组内的所有路由上。中间件...
Route::get('/', function() { return 'Hello World'; }); 基本POST 路由 代码如下: Route::post('foo/bar', function() { return 'Hello World'; }); 注册一个可以响应任何HTTP动作的路由 代码如下: Route::any('foo', function() {