Reputation: 500
I am trying to send a route the old way, without using Blade's {{}} tags. I am encountering a problem, because the framework throws my route as not defined. Can someone help me?
This is my form tag:
<form method="POST" action="{{ route('companyStore') }}">
My route
Route::post('companyStore', 'CompanyController@store');
My controller (the function name might help you undertand)
public function store(Request $request){
$company_name = $request->input('companyname');
$company_sector = $request->input('companyname');
$company_address = $request->input('companyaddress');
$company_phone = $request->input('companyphone');
$company_website = $request->input('companywebsite');
$company_representative = Auth::user()->id;
Company::create([
'name' => $company_name,
'sector' => $company_sector,
'address' => $company_address,
'phone' => $company_phone,
'website' => $company_website,
'representative_id' => $company_representative
]);
$company = Company::where('representative_id', $company_representative)->first();
User::where('id', $company_representative)->update(array('company_id' => $company->id));
return redirect('/admin/home');
}
The error is always:
Route [companyStore] not defined. (View:
Upvotes: 1
Views: 4194
Reputation: 14268
When you use the route
helper, it expects a named route. So define your route as this:
Route::post('companyStore', 'CompanyController@store')->name('companyStore');
or use:
<form method="POST" action="{{ url('/companyStore') }}">
or use:
<form method="POST" {{ action('CompanyController@store') }}>
Upvotes: 3
Reputation: 6341
I don't know why @nakov has propsed {{ url('/companyStore') }}
Just Change
FORM
Route::post('companyStore', 'CompanyController@store');
TO
Route::post('companyStore', 'CompanyController@store')->name('companyStore');
Will just work
Upvotes: 0
Reputation: 889
You can define a route.
Route::post('companyStore', 'CompanyController@store')->name('companyStore');
and use this one:
<form method="POST" action="{{ route('companyStore') }}">
Upvotes: 0