据我所知,这段代码:
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'image' => $data->file('image')
->move(
public_path('images'),
$request->file('image')
->getClientOriginalName())创建一个用户。问题是当我在注册表单中选择图像文件时,我无法将它上传到数据库的配置文件表中。我不知道如何传递代码的最后一行以使其工作:
'image' => $data->file('image')
->move(
public_path('images'),
$request->file('image')
->getClientOriginalName())发布于 2015-07-07 03:27:04
如果要将文件存储在服务器上并将文件路径存储在数据库中,代码可能如下所示。
$user = new User();
$user->name = Input::get('name');
$user->email = Input::get('email');
$user->password = hash(Input::get('password'));
if(Input::hasFile('image')){
$file = Input::file('image');
$file = $file->move(public_path().'/images/',$file->getOriginalFileName());
$user->image = $file->getRealPath();
}
$user->save();
return $user;如果要将图像存储在数据库中,则必须稍微调整一下。
https://stackoverflow.com/questions/31255352
复制相似问题