0
votes

Step 1-Installation: (composer require intervention/image)

Step 2-Configuration: After you have installed Intervention Image, open your Laravel config file config/app.php and add the following lines.

In the $providers array add the service providers for this package. Intervention\Image\ImageServiceProvider::class

Add the facade of this package to the $aliases array.

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

Step 3-Uses: use Image

 public function avatar(Request $request){
    $user = new User();
    if($request->hasFile('image')) {
        if ($user->image){
            unlink(public_path('/image/user/').$user->image);
        }
        $image = $request->file('image');
        $imageName = $image->getClientOriginalName();
        $fileName = $userName . "_profile_". $userId . "_" . $imageName;

        $directory = public_path('/image/user/');
        $imageUrl = $directory.$fileName;
        Image::make($image)->resize(200, 200)->save($imageUrl);
        $user->image = $fileName;
    }

    if ($user->save())
        return redirect()->back()->with('success','Update successfully');

    return redirect()->back()->with('error', 'There is an error message');
}
1
what error you found or what you kind of help you need. please mention in question properly.Yagnik Detroja
what is your problem? do you need help or you want to share your code about how save image?Saengdaet

1 Answers

3
votes

step 2 is not needed if you are working on laravel 5.6 composer require intervention/image will install in your vendor folder and laravel package discovery will do the rest for you