在使用make:auth后,在用户注册过程中使用move()函数


Using move() function in user registration process after using make:auth Laravel 5.3

我在Laravel 5.3中添加了一个文件上传(个人资料图片)到由命令'make:auth'生成的注册表单问题是我得到一个字符串,而不是一个文件,所以我不能使用move()函数来放置文件。

这是我的表单:

<form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}">
    {{ csrf_field() }}
    {!! Form::file('profile_picture', null, ['class' => 'form-control']) !!}
    <div class="form-group{{ $errors->has('first_name') ? ' has-error' : '' }}">
        <input id="first_name" type="text" class="form-control" name="first_name" value="{{ old('first_name') }}" placeholder="First name" required autofocus>
        @if ($errors->has('first_name'))
            <span class="help-block">
                <strong>{{ $errors->first('first_name') }}</strong>
            </span>
        @endif
    </div>
    <div class="form-group{{ $errors->has('last_name') ? ' has-error' : '' }}">
        <input id="last_name" type="text" class="form-control" name="last_name" value="{{ old('last_name') }}" placeholder="Last name" required autofocus>
            @if ($errors->has('last_name'))
                <span class="help-block">
                    <strong>{{ $errors->first('last_name') }}</strong>
                </span>
            @endif
    </div>
    <button type="submit" class="btn btn-primary">Register</button>
</form>

这是我的create user函数:

protected function create(array $data)
{
    $user = User::create([
        'email' => $data['email'],
        'first_name' => $data['first_name'],
        'last_name' => $data['last_name'],
        'password' => bcrypt($data['password']),
        'class' => $data['class'],
        'year' => $data['year'],
        'phone' => $data['phone']
    ]);
    $tags = $data['tags'];
    $user->tags()->sync($tags); //Pivot table of tags
    if($data['profile_picture']){
        $file = File::create(['name' => $data['profile_picture'] , 'user_id' => $user->id]);
        MOVE THE FILE WITH $file->move();
        $file->save();
        $user->files()->attach($file); //Pivot table of files
    }
    return $user;
}

尝试在表单HTML标签中使用enctype="multipart/form-data"