laravel MethodNotAllowedHttpException when do POST on online server - php

I have got MethodNotAllowedHttpException when running on online server, but on local server it runs well.
The PHP version is same, the method is used POST.
The other POST methods are runs well except this one.
on blade.php
<form action="{{ route('update.product') }}" method="POST" enctype="multipart/form-data" class="form-horizontal js-form">
on routes/web.php
Route::post('/updateProduct', [
'uses' => 'AdminController#updateProducts',
'as' => 'update.product'
]);
Update:
After I changed the route into 'get'
Route::get('/updateProduct', [
'uses' => 'AdminController#updateProducts',
'as' => 'update.product'
]);
it reach the updateProducts function.
but of course there is no data to process. So, why my post method form sent the get method? and on the browser developer tools I've got POST?
but on my local server it runs well only on online server I've got this issue.
browser dev tools

Can you try using different method if you use laravel collective.
{!! Form::open(['url' => 'client/store','method'=>'post','id'=>'client-register']) !!}
and in route it must be
Route::post('client/store', 'ClientController#store')>name('client.store').
or you can write your action
action="{{URL::to('client/store')}}"
At first see if routes are define properly.
And also you can try clearing the cache using artisan command.
php artisan config:cache
Hope it helps.

This issue occurs due to a missing module extension PDO database on the server, so upload file into the application will throws error.
Installing the module extension will resolve the issue.

Related

Fresh Laravel Nova returns 419 expired after form submit

I've added Laravel Nova to my Laravel app (v7.x). There is nothing special configured within my middlewares/service providers/etc.
Whenever I submit a form from Nova, it results in a 419 Page expired error.
The VerifyCsrfTokenMiddleware throws an error, saying there is a "CSRF token missmatch".
All views and assets are default as they came by the Laravel Nova installation script.
Any idea, what causes this problem?
I recently faced the same problem. I resolved it by adding the following line to my .env file:
SESSION_DOMAIN=.domain.tld
Where domain.tld is your domain obviously. Don't forget the initial dot.
Also, if you're using Laravel passport and your site is fresh, don't forget to execute php artisan passport:install

Lumen Enable CSRF Token

I know lumen is used to session less API development still i have a situation where i need to enable CSRF token.Session every think works fine but i need to enable csrf token if i add
<input type="hidden" name="_token" value="{{ csrf_token() }}">
in form i got error
(1/1) ReflectionException Class
Laravel\Lumen\Http\Middleware\VerifyCsrfToken does not exist
In bootstrap/app.php i have uncommented following
$app->middleware([
'Illuminate\Cookie\Middleware\EncryptCookies',
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
'Illuminate\Session\Middleware\StartSession',
'Illuminate\View\Middleware\ShareErrorsFromSession',
'Laravel\Lumen\Http\Middleware\VerifyCsrfToken',
]);
even i have enabled
$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
'csrf' => 'Laravel\Lumen\Http\Middleware\VerifyCsrfToken'
]);
if i comment csrf in middleware then i get following error
Call to undefined function csrf_token() in blade
I am using laravel "laravel/lumen-framework": "5.5.*",
can any one help me how i can enable VerifyCsrfToken in lumen
Had this same issue. Posting here if someone in future.
Found out that they removed all csrf stuff from lumen since 5.2 (not exactly sure since which version). To use csrf in Lumen 5.5 or later you need to create yourself or copy VerifyCsrfToken middleware file from laravel package of that specific version (find in github) and place in lumen middleware folder and adjust the path in bootstrap/app.php accordingly.
You may need to install illuminate/cookie or other required package manually as well.
VerifyCsrfToken.php file can be found at laravel/framework/src/illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php
From the lumen documentation Validation
Form Requests
Form requests are not supported by Lumen. If you would like to use form requests, you should use the full Laravel framework.
The Lumen microframework v5.8 don't support form, so it don't have csrf

Route Conflict in Laravel 5.3 on amazon server

My login route is
Route::post('/user/login', array('as' => 'userlogin', 'uses' => 'UserController#login'));
I have debug the code line by line on local server , flow is coming in UserController's login function. It is working perfecly fine on the local server , but as i deployed the source on amazon it is throwing an error
NotFoundHttpException in RouteCollection.php line 161
I have tried many solutions but nothing worked for me. Any suggestions in this regard ?

Laravel 5.2 TokenMisMatchException on Production Server

I am encountering TokenMismatchException on my Production Server, but the application working fine on local Xampp server and another hosting. It our in house server, so we cannot changed it. We have to use it, but we did not understand where is the issue.
Please friends help me, did i need to change anything in server like plugin, extensions or anything else, Please let me know. Here is screen shot below:
Above sceenshot is from Production and one of hosting provider. On production server laravel application giving tokenmismatchexception whereas same application working fine on another hosting provider. We did not understand why this is happening. Please suggest us what to do.
Update:
I have fresh laravel 5.2 and run php artisan make:auth after that i have given 777 permission to the folder, then donw nothing. Still i am getting this exception.
Add this in your html form
<input type="hidden" name="_token" id="_token" value="{{csrf_token()}}">
in blade
{!! Form::token() !!}
And add your route in web middwlware
Route::group(['middleware' => 'web'], function() {
// Place all your web routes here...
});
This is probably the sessions that are not being set properly.
Try to delete your PHP_SESSID cookie or change the way the sessions are stored on the server.
You can also check if sessions are working properly with a testing route.
I had this issue, for me the problem was
SESSION_DOMAIN=custom_domain_here
Setting in my .env file, which was different between production and local. This will cause the sessions to be created incorrectly for the domain and throw a TokenMismatch.
Hope this helps someone.
I had the same problem you have to create token in your configuration file.
Try either built in artisan command $ php artisan key:generate or create the key manually.
Probably you are doing something wrong with user login. Recently I was facing the same problem. In my case the problem that I was using Auth::login($user,true) instead of Auth::login($user) or Auth::attempt...
Secondly you also should check out if you have remember_token column in your user's database.
Thirdly you need to check where your session is stored.
I hope it will help!
I had the same issue, I used
<form role="form" method="POST" action="{{ url('laravel-master/login') }}">
<input type="hidden" name="_token" value="{{ session()->getToken() }}">
This line in my form view.
try to verify your Session file => App/Config
'domain' => 'ip adresse or Domaine name',
and if the domaine name has SSl certification
change the secure variable to True
i hope it will help you :D

Laravel 5.1: Class html does not exist

I am upgrading from 4.2 directly to 5.1 and run into problems with the Html and Form classes.
I followed the upgrade notes, and did
add "laravelcollective/html": "~5.0" to composer.json
composer update
add Collective\Html\HtmlServiceProvider::class to providers in app.php
add Form' => Collective\Html\FormFacade::class,
Html' => Collective\Html\HtmlFacade::class to aliases in app.php
But my views don't work. I get either Class HTML does not exist when using HTML::router or get Class html does not exist when using link_to_route
I also tried Illuminate\html instead of laravelcollective, I did a composer dump-autoload.
The complete errors:
ErrorException in Container.php line 736: Class html does not exist (View: C:\Dev\www\admin\resources\views\clubs\index.blade.php)
ReflectionException in Container.php line 736: Class html does not exist
What am I missing?
I tried everyone's answers and none of them worked for me for some reason. Ultimately I created a completely new laravel application, copied my code and then it started working, So though solved the actual problem remains a mystery.
Add in composer.json
"illuminate/html": "5.*"
and run composer update
Open your config/app.php
add under 'providers'
Illuminate\Html\HtmlServiceProvider::class,
add under 'aliases'
'Form' => Illuminate\Html\FormFacade::class,
'Html' => Illuminate\Html\HtmlFacade::class,
and under your blade templates, use as such
{!! HTML::style('assets/css/flatten.css') !!}
My solution in my case it was problem with CASE-Sensitive class name.
In my config/app.php (in aliases)
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
I am tried to use in view this code:
{!! HTML::mailto('mailto:example#example.com', 'example#example.com'); !!}
and that was an error:
"FatalErrorException in ccf70b1d0b9930d6c4e8f3859fff448f line 11: Class 'HTML' not found"
Name of class 'HTML' is CASE-Sensitive. You should use 'Html' as in your config (config/app.php) file.
Hope this help for some people.
Please change your blade file from this
{{ HTML::style('css/bootstrap.min.css') }}
to
{{ Html::style('css/bootstrap.min.css') }}
It's working.
A simple restart after composer update worked perfectly for me. I was looking for the answer, and got stuck at the same position. I'd suggest, run config:cache and cache:clear and restart the IDE. It will work.
My problem is solved, but the actual cause is still unknown. I have created a completely new laravel install and copied my source (all of it). The new application worked right away (after installing illuminate/html).
So you think I did something wrong with packages? That's what I thought, and then I did a diff on the two directories, only to find out they were identical. So it's a real mystery.
So, now everything is working, I simply renamed my new application and can continue.
I do know at some point I probably had both the collective and the illuminate versions of the HTML package installed. That's what most likely corrupted everything.
this is right way
If you try to use Form::open() or any of the Form methods in a fresh Laravel 5 install, you would get something like this:
http://laraveldaily.com/class-form-not-found-in-laravel-5/
I think I have found the solution.
In your app.php you have declared
'Form' => Illuminate\Html\FormFacade::class,
'Html' => Illuminate\Html\HtmlFacade::class,
While in your View you have called the same class as
{!! HTML::style('css/bootstrap.min.css') !!}
There is nothing wrong with the packages as the marked answer above but rather difference in capitalization of the word HTML as the previous documentation ver 5.0.*.
It should be
'Form' => Illuminate\Html\FormFacade::class,
'HTML' => Illuminate\Html\HtmlFacade::class,
Try it
php artisan cache:clear
php artisan clear-compiled
edit config/app.php
add this into providers
Collective\Html\HtmlServiceProvider::class,
and this into aliases
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,

Categories