我在Laravel上写我的项目。当我优化项目时,我遇到一个问题,即无法准备路由[api / user]进行序列化。使用闭包。
我在web.php中查找了任何闭包,但没有找到任何东西
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/','ReviewsController@main')->name('main');
Route::post('/','MailController@verify')->name('verifyPost');
Route::get('/reviews', 'ReviewsController@index')->name('reviews');
Route::post('/reviews','ReviewsController@add')->name('addReview');
Auth::routes();
Route::group(['middleware' => 'admin','prefix' => 'admin'],function () {
Route::get('/', 'HomeController@index')->name('admin');
Route::get('/reviews', 'Admin\ReviewsController@get')->name('admin.reviews');
Route::get('/reviews/accepted/{id}','Admin\ReviewsController@accept')->where('id','\d+')->name('admin.accepted');
Route::delete('/reviews/delete','Admin\ReviewsController@delete')->name('reviews.delete');
});
答案 0 :(得分:1)
在api.php
文件搜索中并对此路线进行注释,您不会出错。.
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
,并且在web.php
文件route::group
中,也关闭,并对其进行注释以进行测试
Route::group(['middleware' => 'admin','prefix' => 'admin'],function () {
Route::get('/', 'HomeController@index')->name('admin');
Route::get('/reviews', 'Admin\ReviewsController@get')->name('admin.reviews');
Route::get('/reviews/accepted/{id}','Admin\ReviewsController@accept')->where('id','\d+')->name('admin.accepted');
Route::delete('/reviews/delete','Admin\ReviewsController@delete')->name('reviews.delete');
});
查看什么是closure
答案 1 :(得分:1)
Php路由缓存命令:
php artisan route:cache
如果您的应用程序使用基于控制器的路由。它有助于快速执行。但是请记住“无法缓存基于封闭的路由” 因此,请将您的Closure路由转换为控制器类。
答案 2 :(得分:0)
确保检查“ routes / api.php”