PHP Laravel how to use two forms in one view
I'm building aLaravel
-app where I have two forms in oneblade
-template, which appears depending on which tab is active.
It looks like this:
<div data-contact-form-id="1" id="contact-company">
<form method="POST" action="{{ route('contact.company') }}">
// bunch of input fields here
</form>
</div>
<div data-contact-form-id="2" id="contact-private">
<form method="POST" action="{{ route('contact.store') }}">
// bunch of input fields here
</form>
</div>
then myweb.php
Route::post('contact', '[email protected]')->name('contact.store');
Route::post('contact/company', '[email protected]')->name('contact.company');
but I can't submit the "company-contact" form, and when I try to do remove the slash in the route I get an errorroute.store
is not defined:
Route::post('contact', '[email protected]')->name('contact.store');
Route::post('contact', '[email protected]')->name('contact.company');
Why is this and how can I solve this?
Answer
Solution:
put all input fields in a single form and submit to the store route.
In controller:
Here I used the company model & some fields just for example you can replace with your model & your field name