Laravel Stapler,使用User :: create但不是更新

时间:2015-04-24 00:26:36

标签: php laravel-5

在表格中添加我的控制器

        public function add()
        {
            $input = Input::all();
            $validator = Validator::make( $input, User::$rules['create'] ); # Or User::$rules['create']
       if ( $validator->fails() ) {
        return "failure";
        }
                else{          
                return User::create(Input::all());  
                }

        }

在m控制器中的表单编辑

        public function edit()
        {
         $input = Input::all();
        $validator = Validator::make( $input, User::$rules['edit'] ); # Or User::$rules['create']
       if ( $validator->fails() ) {
        return "failure";
        }
                else{
                    $user=new User();
                        $user->find(1);
            $user->update(Input::all());  
                }

        }

在用户模型中

protected $fillable = ['name', 'email', 'password','role','position','mobile_number','picture','facebook','twitter','instagram','linkedin','avatar'];
public function __construct(array $attributes = array()) {
        $this->hasAttachedFile('avatar', [
            'styles' => [
                'medium' => '300x300',
                'thumb' => '100x100'
            ],

                        'url' => '/uploads/:attachment/:id_partition/:style/:filename',
            'default_url' => '/uploads/defaults/:style/missing.png'
        ]);

        parent::__construct($attributes);
    }

此代码适用于添加新用户,但显示错误

Column not found: 1054 Unknown column 'avatar' in 'field list 

我在用户表中有必填字段,并且User::create

上的所有内容都运行良好

编辑:这是我的dd($用户) http://pastebin.com/4e3HSusG

1 个答案:

答案 0 :(得分:0)

从不同的线程获得解决方案

$user = User::find(1);
$user->update(Input::except('avatar'));
$user->avatar = Input::file('avatar');