Route::getCurrentRoute()->getPath();因为Route对象属于请求阶段,而框架将其关联到了 Request 对象上,所以也可以下面这样链式调用:Request::route()->getName();在 Laravel 5.1 内这样写:useIlluminate\Support\Facades\Route;$currentPath= Route::getFacade
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::namespace('Admin')->group(function() {//在 "App\Http\Controllers\Admin" 命名空间下的控制器Route::get('/user', 'UserController@index');//Admin/UserController@indexRoute::get('/user2', 'UserController@user2');//Admin/UserController@user2});//但是不推荐使用这种方法,因为使用的闭包...
Route::get('user/{name}', function($name) { // }) ->where('name', '[A-Za-z]+'); Route::get('user/{id}', function($id) { // }) ->where('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 ...
Route::get('user/{id}/{name}',function($id,$name) { // }) ->where(array('id'=>'[0-9]+','name'=>'[a-z]+')) 定义全局模式 如果希望在全局范围用指定正则表达式限定路由参数,可以使用pattern方法: Route::pattern('id','[0-9]+'); ...
Route::get('/user', 'UsersController@index'); 通过上面的路由我们可以知道,客户端通过以HTTP GET方式来请求 URI "/user"时,Laravel会把请求最终派发给UsersController类的index方法来进行处理,然后在index方法中返回响应给客户端。 上面注册路由时用到的Route类在Laravel里叫门面(Facade),它提供了一种简单的方式...
Route::get('foo', function () { return 'Hello World'; });默认路由文件#所有的 Laravel 路由都在 routes 目录中的路由文件中定义,这些文件都由框架自动加载。在 routes/web.php 文件中定义你的 web 页面路由。这些路由都会应用 web 中间件组,其提供了诸如 Session 和CSRF 保护等特性。定义在 routes/api...