0
I was making a system auth Adjustable that changed the user’s profile photo and the following error appeared:
This is my php code:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
use Image;
use Illuminate\Support\Facades\File;
class UserController extends Controller
{
public function profile(){
return view('partials.alunoform', array('user'=> Auth::user()) );
}
public function update_avatar(Request $request){
// Handle the user upload of avatar
if($request->hasFile('avatar')){
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300, 300)->save( public_path('uploads/avatars/' . $filename ) );
$user = Auth::user();
$user->avatar = $filename;
$user->save();
}
return view('partials.alunoform', array('user'=> Auth::user()) );
}
}
My html:
<div class="row">
<div class="col s6">
<img class="responsive-img hoverable" src="/uploads/avatars/{{ $user->avatar }}">
</div>
</div>
<form enctype="multipart/form-data" action="/profile" method="POST">
<div class="file-field input-field col s6">
<div class="btn indigo">
<span>Escolher foto</span>
<input type="file" name="avatar">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
<button class="btn waves-effect waves-light col s12 red" type="submit" name="action">Confirmar</button>
</div>
</form>
Any hint on how I can fix this?
Same error still persists
– Rafitos
I managed to fix the problem using your code, it was also a path error in public_path
– Rafitos