[英]Using move() function in user registration process after using make:auth Laravel 5.3
I've added a file upload (Profile picture) to the registration form which generated by the command 'make:auth' in Laravel 5.3 The problem is I get a string and not a file so I can't use the move() function to place the file where it should. 我在Laravel 5.3中由命令'make:auth'生成的注册表中添加了文件上传(个人资料图片)问题是我得到的是字符串而不是文件,所以我不能使用move()函数将文件放置在应有的位置。
This is my form: 这是我的表格:
<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>
This is my create user function: 这是我的创建用户函数:
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"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.