Laravel MethodNotAllowedHttpException No message - laravel

I'm getting this error after posting the data.
Route;
Route::post('/classified/location', 'ClassifiedController#locationPost')->name('location-post');
Form;
<form class="form" method="post" action="/classified/location">
#csrf

Please check your route file to make sure that you haven't defined the same route twice, in that case later will replace the prior so make sure route definition is unique and exactly once.
Also if you anyway are naming your routes then use the name itself to target it so use:
<form class="form" method="post" action="{{ route('location-post') }}">
Also, make sure you don't define two or more routes with the same name.

Your form tag like that:
<form class="form" method="post" action="{{route('location-post')}}">
OR
<form class="form" method="post" action="{{url('/classified/location')}}">

Related

The POST method is not supported for this route. Supported methods: PUT. LARAVEL

I would like to send data with PUT method
However, this error happens.
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The POST method is not supported for this route. Supported methods: PUT.
I don't really understand why my code is not correct.
web.php
Route::get('/', function () {
return redirect('/home');
});
Auth::routes();
Route::put('/save_data', 'AbcController#saveData')->name('save_data');
view.blade.php
<form action="{{route('save_data')}}" method="POST">
#method('PUT')
#csrf
<input type = "hidden" name = "type" value ='stack' >
<div>
<button>post</button>
</div>
</form>
when it is changed
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
instead of
#method('PUT')
#csrf
It works well.
make sure to check First Another Route with Same Name
You can make POST route and dont need to put this after form tag #method('PUT')
CHange the Placement of the route before this Auth::routes();
use save_data in route instead of /save_data.
use {{url('save_data')}} in action instead of {{route('save_data')}}.
If you insist on using PUT you can change the form action to POST and
add a hidden method_field that has a value PUTand a hidden csrf field
(if you are using blade then you just need to add #csrf_field and {{
method_field('PUT') }}). This way the form would accept the request.
You can simply change the route and form method to POST. It will work
just fine since you are the one defining the route and not using the
resource group
after all this run artisan command
php artisan route:clear
Change:
<button>post</button>
to:
<button type="submit">post</button>

put query params inside a filter key laravel

hi i want to change this url from get form
http://127.0.0.1:8000/allfiles?category_id=1&file_id=1
to this in laravel
http://127.0.0.1:8000/allfiles?filter[category_id]=1&filter[file_id]=1
how can i do that?
Actually i want change perquery=? to filter[perquery]=?
thanks
Try something like this in the blade (you can modify it if need):
<form action="http://127.0.0.1:8000/allfiles" method="GET">
<input name="filter['category_id']">
<input name="filter['file_id']">
<input type="submit">
</form>

Route not defined in form action in laravel 7

View Form
Form
Routes
Routes
Route list
Route list
Controller
Reg controller
ERROR
Route [] not defined.
if you use resource
{{ route('student.store') }}
if you use ->name("student")
{{ route('student') }}
you have to read carefully the laravel documentation for routes
The form action attribute specifies where to send the form-data when a form is submitted.
so you simply direct submitted data as follow :
<form method="POST" action="student/store">
provided that your route like :
Route::post("student/store", "RegStudentsController#store");
or if you want to use the route:
Route::post("/student", "RegStudentsController#store")->name("student");
<form method="POST" action="{{ route('student') }}">
Update
as per your updated screen shoots the solution will be doing something like:
<form method="POST" action="{{ url('/student') }}">

Mixed content issue in laravel

I have a following form:
<form class="form-horizontal" role="form" method="POST" action="{{ url('/admin/email') }}">
On localhost, it generates https//.... but on server it generates http://... which results in mixed content warning. Is there any flag to fix it ?
<form class="form-horizontal" role="form" method="POST" action="{{ url('/admin/email') }}">
actualy url() accepts three params. string,Array,bool the third params is for secure, means https. you can set it to true.
i hope this helps
If you look at declaration of url method, it's like this
function url($path = null, $parameters = [], $secure = null)
so third parameter is for generating secure URL or not, so your line will be like this
<form class="form-horizontal" role="form" method="POST" action="{{ url('/admin/email', [], true) }}">

How can I use parsley.js with Codeigniter form_open() function?

Actually I want to pass data-parsley-validate as a parameter to form_open() function.
Like <form action="http://recruit.com/controller/add_jobs" accept-charset="utf-8" data-parsley-validate>
Actually, you can init parsleyJS with jQuery:
<form id="form"></form>
<script>
$('#form').parsley();
</script>
So, you dont need to do <form data-parsley-validate></form>
At first load parsley.js in the head of html.
then apply parsley.js in the CI like this:
<form role="form" method="post" id="parsleyForm" data-parsley-validate
action="<?php echo site_url('.........') ?>">
go to this link for details of parsley.js.

Resources