头像始终为空

时间:2017-12-25 17:00:06

标签: php laravel octobercms

尝试使用$ attachOne关系将图像/文件附加到用户。我似乎无法从组件上传文件。这是我的一段代码:

型号:

public $rules = [
        'email'    => 'required|between:6,255|email|unique:users',
        'avatar'   => 'nullable|image|max:4000',
        'username' => 'required|between:2,255|unique:users',
        'password' => 'required:create|between:4,255|confirmed',
        'password_confirmation' => 'required_with:password|between:4,255',
    ];

    public $attachOne = [
        'avatar' => \System\Models\File::class
    ];

    protected $fillable = [
        'name',
        'surname',
        'login',
        'avatar',
        'username',
        'email',
        'telegram',
        'phone',
        'skype',
        'password',
        'password_confirmation'
    ];

组件:

 public function onUpdate()
    {
        if (!$user = $this->user()) {
            return;
        }

        if (Input::hasFile('avatar')) {
            $user->avatar = Input::file('avatar');
        }


        $user->fill(post());           
        $user->save();
        return $redirect;

}

一段default.htm代码:

{{ form_ajax('onUpdate', { model: user,files: true  }) }}
 <input type="file" name="avatar">

1 个答案:

答案 0 :(得分:0)

执行"A1"方法后,您需要执行let tmp : list<string*list<float>> = [0..(mat.Length - 1)] |> List.map (fun i -> string i, mat.[i]) let tmp' = tmp |> List.map (fun (str, x) -> "A" + str, x) let tmp' = tmp' |> namedParams |> R.cbind //let tmp = // tmp // |> namedParams // |> R.cbind tmp // No exceptions 。此外,您需要将文件名保存到DB,而不是文件本身:

$user->avatar