0
votes

I am using Laravel and Intervention to handle a file upload from the user, I have installed Intervention using Composer but when I try to use some of its functions I get this error message Class 'Intervention\Image\Facades\Image' not found I have checked my app.php file and I have added the correct lines of code to aliases and providers but now I am not sure what is the problem

Here is my function

public function postAvatarUpload(Request $request)
    {
         $this->validate($request, [
            'image' => 'required|image|max:3000|mimes:jpeg,jpg,png',
        ]);
        $user = Auth::user();

        $usersname = $user->username;
       $file = $request->file('image');
       // $ext = $file->getClientOriginalExtension();
        $ext= Input::file('image')->getClientOriginalExtension();
        $filename = $usersname . '.' . $ext;
        if (Storage::disk('public')->has($usersname)) {
            Storage::delete($usersname);
        }
           Storage::disk('public')->put($filename, File::get($file));

           $path = public_path('app/public/'. $filename);
            Auth::user()->update([
                'image' => $path,
            ]);
        $resizedImg = Image::make($path)->resize(200,200);
       // $ext = $file->getClientOriginalExtension();

        return redirect()->route('profile.index', 
                ['username' => Auth::user()->username]);
    }
2

2 Answers

0
votes

You also need to import it at the top of the file, after the namespace. Since you say that you've set the facade up, all you need to do is:

use Image;
0
votes

Add facade and provider as described in the documentation. Then run composer dumpauto -o command.

Then add use Image to your class, or use it like this:

$resizedImg = \Image::make($path)->resize(200,200);