Information Technology Questions and Answers Community

Questions/Title


   Asked Questions

Views
184
Answers
0
Action

(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

NotWritableException
Can't write image data to path (/home/vlindr.com/vlindr/public/uploads/avatars/1504691841.jpg)

Anybody knows how to go about fixing this?

My Controller:

<?php
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'
      ]);

     Auth::user()->profile()->update([
     '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(
PHP  
laravel-5  
Date Posted:06 Sep at 06:51  Posted By:Peter 
Views
124
Answers
0
Action
Edit Account
LOGIN INFORMATION
Change Settings
Email Notifications Notifications will be sent to abcd@gmail.com
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