Level 122
change
if($request->Hasfile('avatar')) {
to
if($request->hasFile('avatar')) {
Hi, I was following a tutorial how to create a profile page with the possibility to change the avatar image in the page. But it doesn't work. I'm using laravel and Image intervention package. I have a profile blade view page like this
<div class="col-md-9 col-md-offset-3">
<h2>Profilo di {{ $user->name }}</h2>
<h3>Username:{{ $user->username }}</h3>
<h3>Email: {{ $user->email }}</h3>
</div>
<div class="col-md-9 col-md-offset-3">
<div class="image">
<img src="/img/users/{{ $user->avatar }}" style="width:150px;">
</div>
<form enctype="multipart/form-data" action="/profile" method="POST" >
<label>Aggiorna immagine profilo</label>
<input type="file" name="avatar">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="submit" class="pull-right btn btn-sm btn-primary">
</form>
</div>
The User controller to upload the image
namespace App\Http\Controllers;
use Illuminate\Http\Request;
// Use Auth facede
use Auth;
use Image;
class UserController extends Controller
{
public function profile() {
return view('profile', array('user'=>Auth::user()));
}
public function update_avatar(Request $request) {
// Funzione per la gestione dell'upload
if($request->Hasfile('avatar')) {
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->GetClientOriginalExtension();
$avatar_img = Image::make($avatar);
$avatar_img->resize(200,200)->save(public_path('/img/users/' . $filename));
dd($avatar_img);
$user = Auth::user();
$filename = $user->avatar;
$user->save();
return view('profile', array('user'=>Auth::user()));
}
}
}
Web route file
Route::get('/profile', 'UserController@profile');
Route::post('/profile','UserController@update_avatar');
Basically there no error displayed when I try to upload an image, and the image path is not uploaded in the database. Thanks for any help.
Please or to participate in this conversation.