gpt4 book ai didi

php - Laravel Stapler,处理用户::创建但不更新

转载 作者:可可西里 更新时间:2023-10-31 23:47:22 28 4
gpt4 key购买 nike

在我的 Controller 中添加表单

        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 Controller 中的表单编辑

        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($user) http://pastebin.com/4e3HSusG

最佳答案

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

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

关于php - Laravel Stapler,处理用户::创建但不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29836675/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com