[英]Laravel form route not defined
I am trying to send a route the old way, without using Blade's {{}} tags. 我正在尝试以旧方式发送路由,而不使用Blade的{{}}标签。 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:
When you use the route
helper, it expects a named route. 当您使用
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') }}>
You can define a route. 您可以定义一条路线。
Route::post('companyStore', 'CompanyController@store')->name('companyStore');
and use this one: 并使用这个:
<form method="POST" action="{{ route('companyStore') }}">
I don't know why @nakov has propsed {{ url('/companyStore') }}
我不知道为什么@nakov支持
{{ url('/companyStore') }}
Just Change 只是改变
FORM
形成
Route::post('companyStore', 'CompanyController@store');
TO
至
Route::post('companyStore', 'CompanyController@store')->name('companyStore');
Will just work 会工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.