Skip to content

Class OptimizerChain NOT found#144

Description

@mahmoudmohamedramadan

Hi 馃憢, in RegisterController which comes WITH Laravel, I was want to let the user upload his avatar. everything works well until I installed this package. here is the code

use Spatie\ImageOptimizer\OptimizerChainFactory;

 /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\Models\User
     */
    protected function create(array $data)
    {
        if (request()->hasFile('avatar')) {
            /* store uploaded file, then get the image path */
            $uploadedImage = request()->file('avatar')->store('public/users');
            /* get instance from `OptimizerChainFactory::class` then pass the $uploadedImage to `omptimize()` method */
            $optimizerChain = OptimizerChainFactory::create();
            $imagePath = asset("storage/users/{$uploadedImage}");
            $optimizerChain->optimize($imagePath);
            /* get the image's hash name WITH its extension */
            $data['avatar'] = Str::after($uploadedImage, '/users/');
        }

        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'avatar' => $data['avatar'],
            'password' => Hash::make($data['password']),
        ]);
    }

the data of the user was saved, the uploaded image was stored successfully also, BUT after I've installed this package, this ERROR Class "Spatie\ImageOptimizer\OptimizerChain" not found happens, WHAT should I do?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions