Reputation: 1
So I am following a course from Udemy by Brad about Laravel, and while it is from almost two years ago now, many people recommended it to me because everything is still relevant. In one of his lessons, he uses this composer code called Intervention, which allows you to resize an image a user has/is submitting to your DB.
Now in the controller, he uses the class use Intervention\Image\Facades\Image;
and on his screen it works, but when I use the same class, laravel spits out this code error Class "Intervention\Image\Facades\Image" not found.
I am using the class on this function:
public function storeAvatar(Request $request) {
$request->validate([
'avatar' => 'required|image|max:7500'
]);
$imgData = Image::make($request->file('avatar'))->fit(120)->encode('jpg');
Storage::put('public/examplefolder/cool.jpg', $imgData);
}
I have redownloaded Intervention, updated Composer, cleared cache, and nothing seems to work. Does anyone know any way to get rid of this issue?
Here is also the blade.php template I am using for more context:
<div class="container container--narrow py-md-5">
<h2 class="text-center mb-3">Upload a New Avatar</h2>
<form action="/manage-avatar" method="POST" enctype="multipart/form-data">
@csrf
<div class="mb-3">
<input type="file" name="avatar" required>
@error('avatar')
<p class="alert small alert-danger shadow-sm">
{{ $message }}
</p>
@enderror
</div>
<button class="btn btn-primary">Save </button>
</form>
</div>
Upvotes: 0
Views: 739
Reputation: 90
You most likely did composer require intervention/image as opposed to composer require intervention/image-laravel // this is used in v3.
Upvotes: 1
Reputation: 121
Try using "use Intervention\Image\Laravel\Facades\Image;" I think you're using code for v2.x for the Intervention/image-laravel if you look for the updated version you can see in this link github.com/Intervention/image-laravel that the example controller has a different path (the one i mentioned above
use Intervention\Image\Laravel\Facades\Image;
Route::get('/', function () {
$image = Image::read('images/example.jpg');
});
Upvotes: 0