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.
This is my form:
<form class="form-horizontal" role="form" method="POST" action="">
{!! Form::file('profile_picture', null, ['class' => 'form-control']) !!}
<div class="form-group">
<input id="first_name" type="text" class="form-control" name="first_name" value="" placeholder="First name" required autofocus>
@if ($errors->has('first_name'))
<span class="help-block">
<strong></strong>
</span>
@endif
</div>
<div class="form-group">
<input id="last_name" type="text" class="form-control" name="last_name" value="" placeholder="Last name" required autofocus>
@if ($errors->has('last_name'))
<span class="help-block">
<strong></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;
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire