PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 5, 2022

[FIXED] Laravel 5 - web and API Route conflict

 January 05, 2022     api, laravel-5     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing