如何使用Laravel 4创建文件输入并存储到数据库中


How to create a file-input and store into database using Laravel 4?

到目前为止,由于某种原因,

我无法将其保存到数据库。

我已经检查了所有内容。

谁能告诉我我做错了什么?

但是由于某种原因,该文件已保存到我的本地系统。

$user                = new User;
        $user->firstname = Input::get('firstname');
        $user->lastname  = Input::get('lastname');
        $user->username  = Input::get('username');
        $user->email     = Input::get('email');

$logo_path = Input::file('logo_path');
        if (Input::hasFile('logo_path'))
        {
            $file            = Input::file('logo_path');
            $destinationPath = base_path().'/app/files/logo_path/';
            $filename        = $file->getClientOriginalName();
            $uploadSuccess   = $file->move($destinationPath, $filename);
            $user->logo_path = $filename;
        }
            return Redirect::to('/users/')
            ->with('success',' Your Account has been created');
        }

我注意到你忘记了一件最重要的事情。

在返回重定向之前尝试此$user->save();。让我知道。

你没有执行 save() 方法,你的代码应该是

$user = new User;
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->username = Input::get('username');
$user->email = Input::get('email');
if (Input::hasFile('logo_path'))
        {
            $allowedext = array("png","jpg","jpeg","gif");
            $photo = Input::file('logo_path');
            $destinationPath = public_path().'/uploads';
            $filename = str_random(12);
            $extension = $photo->getClientOriginalExtension();
            if(in_array($extension, $allowedext ))
            {
                $upload_success = Input::file('logo_path')->move($destinationPath, $filename.'.'.$extension);
            }
}

$user->照片 = $filename ;$user->保存();请注意变量名称