Information Technology Questions and Answers Community

How to store avatar correctly

(in developer mode) The way I have my Controller now it stores the new image path to the database but doesn't upload it to the 'uploads/avatars' folder.

Also when I try to just edit the profile without uploading a new avatar, it throws an ErrorException undefined variable:avatar,

and the version i have on my hosting server also throws the Errorexception if not uploading but only editing the profile,

And if I try to upload a new avatar it tells me

Can't write image data to path (/home/

Anybody knows how to go about fixing this?

My Controller:

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Auth;
use Session;
use Image;
use Illuminate\Support\Facades\File;
use App\User;
use DB;

class UserController extends Controller

        public function __construct()
        $this->middleware('auth', ['except' => ['index', 'show']]);

     public function index(){
        return view('profiles.profile', array('user' => Auth::user()) );

   public function edit()


return view('profiles.edit')->with('info', Auth::user()->profile);

     public function update(Request $request)

     $this->validate($request, [
      'location' => 'required',
      'about' => 'required|max:355',
      'passion' => 'required|max:355'

     'location' => $request->location,
     'about' => $request->about,
      'passion' => $request->passion


 $user = User::find(Auth::user()->id);

// Handle the user upload of avatar

if ($request->hasFile('avatar')) {
    $avatar = $request->file('avatar');
 $filename = time() . '.' . $avatar->getClientOriginalExtension();


    // Delete current image before uploading new image

 if ($user->avatar !== 'man.png' && $user->avatar !== 'woman.png')
     $file = public_path(Add Comment -->
PHP         laravel-5        
Your Answer: 

0 Answers
Edit Account
Change Settings
Email Notifications Notifications will be sent to
Select option for your email notifications:
Mature / News Filter We'll send on email when new jobs are posted
Option 2 for email notification We'll send on email when new jobs are posted