user9752285
user9752285

Reputation:

Class 'Image' not found laravel 5.3

Using laravel 5.3

FatalErrorException in UserProfileController.php line 26: Class 'Image' not found

I actually have added use Image;

namespace App\Http\Controllers\Profile;

use App\Photo;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Image;



class UserProfileController extends Controller
{
    //
    public function profile(){
        return view('profile', 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('profile', array('user' => Auth::user()) );
    }
}

Upvotes: 5

Views: 15076

Answers (2)

foram kantaria
foram kantaria

Reputation: 786

Step 1: Installation In this step you will have to configure intervention/image library in your application.

You will have to run below command in your terminal promt.

composer require intervention/image

Now i assume that you have successfully installed by above command.

OK, now i will configure service provider with their aliases name in following path config/app.php .

config/app.php Add this service provider in provider array :

'Intervention\Image\ImageServiceProvider'

Now add facade to aliases array.

'Image' => 'Intervention\Image\Facades\Image'

Upvotes: 0

Leo
Leo

Reputation: 7420

composer require intervention/image then open the config/app.php file.

Add this to the $providers array.

Intervention\Image\ImageServiceProvider::class

Next add this to the $aliases array.

'Image' => Intervention\Image\Facades\Image::class

then composer dump-autoload and make sure you call it at the top of your controller : use Intervention\Image\ImageManagerStatic as Image;

Upvotes: 10

Related Questions