the following route when i submit a form is working fine
Route::put('/autorisation', 'AdministratifController#update_autorisation')->name('administartif.updateautorisation');
but i'm wondering why when i try to access http://example.com/autorisation
it throws
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message
insted of page not found
it's not about the form it's about going to a browser and type example.com/autorisation and then u get that error of no message in place of 404
PS: in my routes i didn't define this Route::get('/autorisation')
By accessing the page yourself, you do a GET HTTP request instead of a PUT.
You need to set the route as GET instead of PUT.
You are defining the route as PUT but you are trying to use it like a GET route. That's why you are getting MethodNotAllowed.
If you want to show a 404 error instead this MethodNotAllowed (it would be a Whoops when DEBUG=false) you should handle it in your handler.
Edit report method at App\Exceptions\Handler to looks like this:
public function report(Exception $exception)
{
if ($exception instanceof MethodNotAllowedHttpException) {
abort(404, 'Page not found');
}
return parent::report($exception);
}
Please change your route and try this:
Route::post('autorisation', 'AdministratifController#update_autorisation')->name('administartif.updateautorisation');
Related
I have an error, like the error below:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: PUT.
I know that's a error from routes, but I can't see anything in laravel.log.
Here I saw that Laravel doesn't report some things, but my Exceptions/Handler.php file is like this:
protected $dontReport = [
//
];
How do I report everything in laravel.log?
Laravel 6
All exceptions are handled by the App\Exceptions\Handler class. Use the report method to log exceptions.
public function report(Throwable $exception)
{
Log::error($exception); // add this line here
parent::report($exception);
}
See more from docs here
I have a route that supports PUT:
Route::put('/products/{id}/cancel/', 'ProductController#cancel')->where('id', '[0-9]+');
After the Controller updates the state of the product it should redirect to another route:
return redirect('products')->with('success', 'Produto cancelado');
that points to
Route::get('/products', 'ProductController#list')->name('products');
All is working until the Redirect.
The product is updated but the redirect gives a method not supported error:
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
The PUT method is not supported for this route. Supported methods: GET, HEAD
I've also tried the following redirects:
return redirect('/products/')->with('success', 'Produto cancelado');
and
return redirect()->route('products')->with('success', 'Produto cancelado');
How is the method PUT passed? Should I explicitly invoke the GET method in the redirect?
How should I solve this?
EDIT:
I'm sending the PUT from a HTTPrequest. So I'm returning to the JS function. I want to forward to a view that accepts the with->.
EDIT2:
I can return a view but it only appears on the network>preview of the Developer Tools.
return view('pages.products')->with('success', 'Produto cancelado');
But I need it in the window obviously.
I could redirect in the js but that way I miss showing the flash messages in the partial blade.
I don't know what to do.
Thanks
The error is not in the GET method. the error says put method is not supported
Route::put('/products/{id}/cancel/', 'ProductController#cancel')->where('id', '[0-9]+');
If you try this as domainname.com/products/5/cancel then define it as below.
Route::get('products/{id}/cancel', 'ProductController#cancel')->where('id', '[0-9]+');
I ended up doing some cheating:
I added a new PUT route:
Route::put('/products', 'ProductController#list')->name('products_put');
the controller returns:
return redirect()->route('products')->with('success', 'Produto cancelado',200);
and the reponse handler does the cheating:
document.write(this.responseText);
window.history.pushState('products', 'eBaw ยท online shopping', '/products');
Currently have a POST route setup in Laravel
Route::post('/confirm', 'MainController#confirm');
'/confirm' makes use of some POST information sent over from the previous page.
What I am trying to accomplish is, if a user just types in 'index/confirm' into the url and not all of the POST info is present redirect to 'index'
I have the below code and cannot see why this would not work. I think it may be because inorder for the route to trigger at least some POST info needs to be present and if none is then error.
$input = $request->all();
if ( !isset($input) ) {
return redirect('');
}
Error message:
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message
/Users/&name/Desktop/$filepath/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php
protected function methodNotAllowed(array $others)
{
throw new MethodNotAllowedHttpException($others);
}
Commenters answered my question. Needed a seperate route for GET to handle unallowed user submitted url requests.
Route::get('/confirm', 'MainController#index');
That's fine for guarding one endpoint, but there's a more sweeping solution you can apply. Look to your App\Exceptions\Handler class. The render() method is given an awareness of the failed request, and the specific error that was thrown. public function render($request, Exception $e) .... Add this:
if ($e instanceof Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
return redirect('/index');
}
Just be careful with this. If you typo your redirect URL, you'll end up in an infinite loop. I'd also recommend an additional condition that respects the value of config('app.env') for debugging purposes.
I need to save an image, consider that the image arrive correctly from a request, after that I need to save in storage/app.
Below the code in controller class:
public function getImage(ImageRequest $request)
{
$path = $request->image->storeAs( 'images','img.jpg','local');
}
i see this error without nothing saved:
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Call to a member function storeAs() on null
Call to a member function storeAs() on null
This error tells you that you are trying to call the storeAs() method on a null object, which means $request->image is null/doesn't exists.
I am using Laravel 5.0. Is there any way to forward to default 404 page error if the user wrong url. I want to forward all the time if the user entered wrong url in my project.
In your resources/views/errors folder make sure you have a 404.blade.php file and if that is not there then create it and put something in this file.
Basically, if that 404 file is not present there then You'll see an error like this:
Sorry, the page you are looking for could not be found.
NotFoundHttpException in Application.php line 901:
....
.
Sepending on your environment setup. FYI, in app\Exceptions\Handler.php file the handler method handles/catches the errors. So check it, you may customize it, for example:
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
// You can use/catch this but basically this is not included in Handler
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class Handler extends ExceptionHandler {
//...
public function render($request, Exception $e)
{
// Customize it, extra code
if ($e instanceof AccessDeniedHttpException) {
return response(view('errors.403'), 403);
}
// The method has only this line by default
return parent::render($request, $e);
}
}
Then, make sure, the 403.blade.php is also available in your resources/views/errors directory.