Error updating profile photo laravel

0

I was making an auth larial system that changed the profile picture of the user and the following error occurred:

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 tips on how to solve this?

    
asked by anonymous 04.11.2017 / 04:24

1 answer

0

Add

->getRealPath()

It looks like this:

 Image::make($avatar->getRealPath())->resize(300, 300)->save( public_path('uploads/avatars/' . $filename ) );
    
04.11.2017 / 04:52