[英]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>
這是我的創建用戶函數:
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.