I'm building a Laravel
-app where I have two forms in one blade
-template, which appears depending on which tab is active.
It looks like this:
<div data-contact-form-id="1" class="contact-form" id="contact-company">
<form method="POST" action="{{ route('contact.company') }}">
// bunch of input fields here
</form>
</div>
<div data-contact-form-id="2" class="contact-form" id="contact-private">
<form method="POST" action="{{ route('contact.store') }}">
// bunch of input fields here
</form>
</div>
then my web.php
Route::post('contact', 'ContactController@store')->name('contact.store');
Route::post('contact/company', 'ContactController@company')->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 error route.store
is not defined:
Route::post('contact', 'ContactController@store')->name('contact.store');
Route::post('contact', 'ContactController@company')->name('contact.company');
Why is this and how can I solve this?
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
public function store(Request $request){
$post = $request->all();
Company::create([
'company_name' => $post['company_name']
'company_email' => $post['company_email'],
'company_phone' => $post['company_phone']
]);
// another model for contact
Contact::create([
'name' => $post['name'],
'email' => $post['email'],
'phone' => $post['phone'],
]);
}