我正在使用laravel构建网站,尝试上传图片时出现此错误。我是一个初学者,可以帮忙吗?
//file1.cpp
int var_1=getDB(" Table_name","column_name");
...
//file2.cpp
int var2=func2(var_1);
...
//filen.cpp
int var_n=funcn(var_n_1);
答案 0 :(得分:2)
$ user-> name = $ request('name'); 由于$
,$ request是变量而不是func答案 1 :(得分:0)
因为您没有遵循PHP中的naming rules:$ request('name')。
我想您将使用$ request-> get('name')
对于上传图像,您可以使用以下代码,尽管我更喜欢使用Intervention Image
//Auth::loginUsingId(1); #You can test your code without a real login
$data = $request->only(['name']);
if (request()->hasFile('image')) {
$file = request()->file('image');
$fileName = md5($file->getClientOriginalName() . time()) . "." . $file->getClientOriginalExtension();
$destinationPath = public_path('/images/'); //// I assume you have a folder named images in public.
$file->move($destinationPath, $fileName);
$data['avatar'] = $destinationPath.$fileName; // I assume you have a field named avatar in users table.
}
return $data; // Try this line for a better understanding then comment it
Auth::user()->update($data);