Issue
In one of my website in laravel. I facing error 419 when i called login api below my search web route Route::get('/{address_1}/{address_2?}/{address_3?}/{address_4?}'); Route::post('/{address_1}/{address_2?}/{address_3?}/{address_4?}');
And Below Api Route
Route::post('login', 'Auth\PassportController@login'); Route::post('register', 'Auth\PassportController@register');
Solution
In Laravel, a 419 HTTP error code is usually a sign that you are missing a CSRF token.
If the 'API' routes:
Route::post('login', 'Auth\PassportController@login');
Route::post('register', 'Auth\PassportController@register');
Are in your web.php
file then this is likely because the RouteServiceProvider
wraps the routes in your web.php
file inside the web
middleware which has the CSRF middleware enabled.
If this is the case, you will either need to include a CSRF token in your POST request, move these routes to the api.php
routes file, or add the register
endpoint to the $excludes
array of the VerifyCsrf
middleware.
update Actually, your search routes are going to cause a lot of grief. Given the fact that they can match any URL with one to four segments, your API routes are getting swallowed by these. What you will need to do is alter your RouteServiceProvider to register web routes last and then put your search routes last. This way, your pre defined routes will be registered before your “catch-all” search routes.
Answered By - James
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.