Problem with Laravel 5.5 - API Routes

Asked

Viewed 570 times

1

all right?

I’m here again with a new problem... I’m using the Laravel 5.5 and in the process I’m having problems in the routes using the API middleware.

To illustrate, my web.php file is as follows:

<?php

Route::get('/', function () {
    return view('welcome');
});

Route::group(['middleware' => ['cors', 'api'], 'prefix' => 'api'], function()
{
    Route::get('/', function () {
        return response()->json(['message' => 'Jobs API', 'status' => 'Connected']);;
    });

    Route::post('auth/login', 'AuthController@login');
});

I’m testing via Postman the routes, if I put the route

http://192.168.15.253:8091/sys-pesquisa/public/api/

I have the following return:

{
    "message": "Jobs API",
    "status": "Connected"
}

If I try to access the Route "POST" (auth/login) I get the following message:

The page has expired due to inactivity. 

Please refresh and try again.

I realized that changing from POST to GET leaving..

Route::get('auth/login' .........

I got the positive feedback:

{"result":false,"errors":["The senha field is required.","The usuario field is required."]}

But as that is an API that will be accessed via mobile app need q be sent via POST.

Anyway, I have no idea what can be, I researched and found some things talking about the class 'Verifycsrftoken', including even added this excerpt in the class Verifycsrftoken:

protected $except = [
        'api/*'
    ];

But I didn’t succeed... Someone can help me?

Thank you guys!!!

  • When you tested the POST method you put the prefix "api"? The Laravel has set by default a prefix in Routeserviceprovider, you can change or even remove it.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.