【发布时间】:2014-10-08 11:26:28
【问题描述】:
我在 Laravel 中使用的照片上传系统遇到了一些问题。到目前为止,我已经将文件输入并保存在 public/images/profiles 中,但我不知道如何将它插入到带有正确信息的数据库中。目前我收到“调用未定义方法 Illuminate\Database\Eloquent\Collection::save() ”错误。
在我的控制器中,我目前正在尝试通过这样做来插入它:
public function updatePhotos($id)
{
if(Input::hasFile('image'))
//If file is being added
{
$extension = Input::file('image')->getClientOriginalExtension();
$fileName = str_random(9).'.'.$extension;
$user = User::find($id);
$user->profile->photo->type = 1;
$user->profile->photo->filename = $fileName;
$user->profile->photo->save();
Input::file('image')->move('public/images/profiles/',$fileName);
}
}
在照片模型中:
public function profile()
{
return $this->hasOne('Profile');
}
在配置文件模型中,我有:
public function photo()
{
return $this->hasMany('Photo','user_id','user_id');
}
任何人都可以为我发送正确的课程吗?
谢谢
【问题讨论】:
标签: php file-upload laravel-4 eloquent