Laravel post route returning error 500 - laravel

my route
Route::post('register', function()
{
return "POST SUCCESS!";
});
works fine if I chane it to "get".
As soon as I change it to post (and use postman to actually send a post request) I get an error 500.
Its driving me crazy and I cant find the answer..
There is also nothing in the php error log... o_0

Make sure you have created .env file for local environment.
Take a look at storage/logs/laravel.log, you should find error there, e.g.:
cat storage/logs/laravel.log | grep "\[201

Related

How to debug unwanted 302 redirect from Ajax request?

I'm trying to get data from a database through this ajax request:
axios.get('/about-info')
web.php:
Route::get('/about-info', [CMSController::class, 'aboutInfo']);
CMSController.php:
public function aboutInfo()
{
$data = DB::table('about_info')->first('order by id desc');
return $data;
}
but instead I am getting the whole welcome.blade.php content. It looks like the url in web.php is not called and instead a redirect happens. The dev tools network tab shows a 302 redirect.
This thread seems to have insight on this issue. I've been trying to implement answer 3 (adding accept: 'application/json to the config/headers object of the request) but the object already has that entry:
config:
headers:
Accept: "application/json, text/plain, */*"
This guide is talking about auth middleware being the possible cause of this problem but I'm not using middleware (at least none I am aware of). Any idea how to get to the root of this?
Have you tried moving the route to your api routes file? All routes in the web namespace receive session state, CSFR, and possibly more that could be getting in the way (i.e. "new session, go to the welcome screen!").
This would change your URL path to:
axios.get('/api/about-info')
Turns out that web.php was not working at all because of caching issues. Running:
php artisan route:clear
made it work again and showed every problem, which could not be detected before clearing the cache.

Laravel api - 405 not allowed shared hosting

I'm new to Laravel and i have the next problem.
I have an API POST route that works properly in the localhost. I send POST requests from POSTMAN:
Route::group(['middleware' => 'api_import'], function () {
Route::get('/products', [ArticlesController::class, 'index']);
Route::post('/products', [ArticlesController::class, 'addOrUpdateArticles']);
Route::post('/categories', [CategoriesController::class, 'addOrUpdateCategories']);
});
However, it will not work on hosting. Hosting is shared, and I get the message:
When json contains a couple of products everything works properly. When json contains a complete table of 3500 products I get this error.
It is possible that there is a redirect on the page. You should confirm this through the network tab in your browser, because any POST request with a redirect is considered a GET request, so an error appears (405 Method Not Allowd)

Why Laravel reply 200 http code when MethodNotAllowedHttpException?

Why Laravel reply 200 http code when MethodNotAllowedHttpException?
I Would like to recieve a diferent code, like 500.
I consume laravel routes using angular or postman, and recieve 200 code and is dificult to deal with this.
Below one example:
This is not a error, but the usage of the dd() dump and die helper method. This will always return a 200.
Find all dd(); methods in your project and it should work and return a proper error code. But secondly due to that error being thrown, it could seem like your url is invalid and or not allowing POST calls.

Root Security Issue

simple question :if you make post route and try to access it from google chrome it give me No Message error
example :
Route::post('/Login', 'User#Login');
localhost/Login
if i access it from Postman as post request it give what i want
if i access it from Postman as get request
or
if i access it from GoogleChrome (" which is Get Request ")
it return No message error
what i want to redirect any one try to access any route as get to 404notfound page
attached image for the error
I believe that once you set your environment to production, the route will give you a HTTP 405 Method Not Allowed response, not sure how you would change it to a 404.
So in your .env you must set APP_ENV to equal production. Like so:
APP_NAME=Laravel
APP_ENV=production
APP_KEY=[encryption key]
APP_DEBUG=false
APP_URL=http://localhost
I haven't tested this but maybe you can set another route for the GET version which would return the 404.
Route::get('/Login', function() {
return abort(404);
});

MethodNotAllowedHttpException with lucadegasperi/oauth2-server-laravel's included AccessTokenFlow POST route

This is my first Laravel project I'm on, and it has been a ton of fun so far.
I'm setting up an OAuth2 server. I have copied the code posted here in to my routes file.
Via this block of code...
Route::post('oauth/access_token', function()
{
return AuthorizationServer::performAccessTokenFlow();
});
I have tried doing http://local.server.com/oauth/access_token and a "MethodNotAllowedHttpException" error.
If there is any other information I could provide that would help you help me, please tell me!
Cheers
If you are typing http://local.server.com/oauth/access_token into the browser URL bar, then you are sending the request:
GET oauth/access_token
However, your route handles a POST request, and since there is no GET route defined, Laravel is responding with MethodNotAllowedHttpException
In order to properly test your route, you will need to send a POST request.

Resources