如何解决路由和中间件-位置从5.2版更改到5.3版
我当前正在将Laravel应用程序从5.2升级到当前版本(7.x)。实际上,我正在从Laravel 5.4升级到5.5。现在我意识到,在5.3中,routes.php
(以前的app\Http
)的位置更改为routes\web.php
和routes\api.php
。
我在将不同的路由传输到特定文件时遇到麻烦。
我已将routes
文件夹的文件复制到项目中,并将RouteServiceProvider
更改为5.5(https://github.com/laravel/laravel/blob/5.5/app/Providers/RouteServiceProvider.php)的github代码:
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* This namespace is applied to your controller routes.
*
* In addition,it is set as the URL generator's root namespace.
*
* @var string
*/
protected $namespace = 'App\Http\Controllers';
/**
* The path to the "home" route for your application.
*
* @var string
*/
public const HOME = '/home';
/**
* Define your route model bindings,pattern filters,etc.
*
* @return void
*/
public function boot()
{
//
parent::boot();
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
//
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state,CSRF protection,etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
}
我以前的routes.php
看起来像这样:
<?php
Route::group(['middleware' => 'web'],function () {
// all web routes without authorization go here:
...
Route::group(['middleware' => 'auth'],function () {
// all routes which need authorization go here:
...
});
});
现在,我已将所有未经授权的路由放入web.php
,并将所有需要授权的路由放入api.php
文件。
但是此配置不起作用。它不显示页面。
疯狂的是,也不会产生错误日志,因此laravel.log
为空。
RouteServiceProvider
出了什么问题,或者我必须更改我的路线又可以正常工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。