search

Home  >  Q&A  >  body text

Issues related to Laravel's own authentication

The website realizes the separation of front-end and back-end, and only calls back-end services through the API.
The back-end service is written in PHP framework Laravel5.2.

Route::group(['middleware' => ['web']], function () {
    //
    Route::get('/', function () {
        /* 返回前端应用资源 */
        return "Hello";
    });
});

Route::group(['middleware' => ['api']], function () {

    /* 不用认证就可以访问的路由 */
    Route::post('/auth/login', 'Auth\AuthController@login');
    Route::post('/auth/register', 'Auth\AuthController@register');

    /* 需要认证才可以访问的路由 */
    Route::group(['middleware' => ['auth']], function () {
        Route::get('/c', function () {
            return "课程链表";
        });
    });
});

The above code calls

{
  "email": "admin@a.com",
  "pasword": "adsf"
}

Why can't json data be returned?


There are also middlewaresapiWhat is the difference between web?

PHP中文网PHP中文网2740 days ago852

reply all(1)I'll reply

  • 迷茫

    迷茫2017-05-16 16:56:12

    See: https://laravel.com/docs/5.2/responses#json-responses


    Oh, sorry, submitted a request and should have added this

    $.ajax({
        type: 'POST',
        contentType: "application/json",
        dataType: 'json',
        ...
    });

    reply
    0
  • Cancelreply