【发布时间】:2019-11-14 16:13:37
【问题描述】:
我无法通过 laravel 控制器中的存储功能提交表单信息。表单需要为注册用户创建一个新的配置文件。
我什至重新创建了项目,并重做了表单 - 回到纯 html,因为我怀疑 laravelCollective 函数可能会导致它,但仍然是相同的错误。
我什至按照另一个帖子/线程中的建议重新排列了表单属性。
我什至重新创建了项目,并重做了表单 - 回到纯 html,因为我怀疑 laravelCollective 函数可能会导致它,但仍然是相同的错误。
我什至按照另一个帖子/线程中的建议重新排列了表单属性。
形式:
< form method="POST" enctype="multipart/form-data" action="{{ url('users/profile') }}" accept-charset="UTF-8" >
@csrf
...
// input fields here
...
< /form >
路线:
Route::resource('users/profile', 'ProfileController');
Route::get('/home', 'HomeController@index')->name('home');
Route::resource('users', 'UserController');
Route::post('users/profile', 'ProfileController@store')->name('profile.store');
ProfileController@store 函数: //省略部分代码
public function store(Request $request)
{
$this->validate($request, [
'firstname'=>'required',
'lastname'=>'required',
...
'desc'=>'required'
]);
//handle file upload
if($request->hasFile('cover_image')) {
//Get file name with extension
$fileNameWithExt = $request->file('cover_image')->getClientOriginalName();
//Just file name
$fileName = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
//Just Ext
$ext = $request->file('cover_image')->getClientOriginalExtension();
//FileName to Store
$fileNameToStore = $fileName.'_'.time().'_'.$ext;
//upload image
$path = $request->file('cover_image')->storeAs('public/users/'.auth()->user()->id.'cover_images/'.$request->input('firstname').'_'.$request->input('lastname').'_'.auth()->user()->id.'/',$fileNameToStore);
} else {
$fileNameToStore = 'noimage.jpg';
}
/*
*/
$profile = new Profile;
$profile->firstname = $request->input('firstname');
$profile->lastname = $request->input('lastname');
...
$profile->desc = $request->input('desc');
$profile->save();
return redirect('/users/profile');//->with('success','Profile Created');
}
著名的错误:
Symfony\Component\HttpKernel\Exception\ MethodNotAllowedHttpException 不支持 PUT 方法 路线。支持的方法:GET、HEAD、POST。
不确定是什么导致了错误,感谢帮助。
【问题讨论】: