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.2 使用...
Route::get('user/{id}', function($id) { return 'User '.$id; }); 可选路由参数 代码如下: Route::get('user/{name?}', function($name = null) { return $name; }); 带有默认值的可选路由参数 代码如下: Route::get('user/{name?}', function($name = 'John') { return $name; })...
Route::get('/', function() { return 'Hello World'; }); 基本POST 路由 代码如下: Route::post('foo/bar', function() { return 'Hello World'; }); 注册一个可以响应任何HTTP动作的路由 代码如下: Route::any('foo', function() {
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的基于约定的隐式模型解析来使用模型绑定。 我们还可以显式定义路由的参数与模型对...
$request->route()->getAction(); #获取路由类和方法名 $request->route()->getActionName() 1. 2. 3. 使用Input 类 Input::url(); 使用$_SERVER获取基础路由 // path:/platforms?a=1 $_SERVER['REQUEST_URI'] // 获取当前基础路由,比如http://a.com/test/a返回http://a.com ...
Route::get('user/{name}', function($name) { // }) ->where('name', '[A-Za-z]+'); Route::get('user/{id}', function($id) { // }) ->where('id', '[0-9]+'); 路由过滤器 路由过滤器提供了一种限制访问指定路由的简单的方法,这在您需要为您的站点创建需要认证区域的时候非常有用...
Route::get('user/{id}/{name}', function($id, $name) { // }) ->where(array('id' => '[0-9]+', 'name' => '[a-z]+')) 定义全局模式 如果希望在全局范围用指定正则表达式限定路由参数,可以使用 pattern 方法: 代码如下: Route::pattern('id', '[0-9]+'); ...