Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to prepare route [api/user] for serialization. Uses Closure

I'm writing my project on Laravel. When I optimize the project, I have a problem :

Unable to prepare route [api/user] for serialization. Uses Closure.

I looked for any closures in web.php, but I didn't find anything

    <?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');
});
like image 898
Даниил Кикимов Avatar asked Dec 21 '18 06:12

Даниил Кикимов


1 Answers

in api.php file search and comment this route you will not get error..

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

and also in web.php file route::group is also closure and also comment them for test

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');
});

see what is closure

like image 170
Jignesh Joisar Avatar answered Sep 17 '22 16:09

Jignesh Joisar