Issues related to Laravel's own authentication
PHP中文网
PHP中文网 2017-05-16 16:54:12
0
1
835

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中文网

认证0级讲师

reply all(1)
迷茫

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',
    ...
});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!