Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kendrick's avatar

App\Jobs Class not found

I am handling an image upload through a Job, somehow my Controller can't find the Job class, even though I am using it.

What could be the problem? I am also facing problems with my queues table, where no jobs will be stored, for example my SendVerificationMail Job worked, but was not stored within the table.

uploadLogo method

use App\Jobs\UploadLogo;

public function uploadLogo(Request $request, Partner $partner){

// Validation

if($request->hasFile('logo')){
        if ($request->file('logo')->isValid()) {
            $request->file('logo')->move(
            storage_path() . '/uploads',
            $fileId =  uniqid(true) . '.png'
        );
                  
            dispatch(new UploadLogo($partner, $fileId));
        }
        }

        return redirect('partner.profile.logo'); 
}   

Error:

Class 'App\Jobs\UploadLogo' not found
0 likes
55 replies
rin4ik's avatar

show your uplod logo file? from App\Jobs\UploadLogo

kendrick's avatar

I had a typo within the Job file, solved it now, but the redirect always fails. I'm handling my Partner Uploads with this route:

Route::get('partner.profile.logo', [
    'uses' => 'PartnerProfileController@getPartnerLogo', 
    'as' => 'partner.profile.logo',
    'middleware' => ['auth:partner'],
]);

Route::post('partner.profile.logo', [
    'uses' => 'PartnerProfileController@uploadLogo', 
    'middleware' => ['auth:partner'],
    ]);

It uploads the file within my storage folder, but then redirects to the 'partner.profile.logo' route, but within my default guard system, which means it spits an 404.blade view @rin4ik

UploadLogo (Job)

public function handle()
    {
        $path = storage_path() . '/uploads/' . $this->fileId . '.png';
        $filename = $this->fileId . '.png';

        Image::make($path)->fit(250, 250, function ($c) {
            $c->upsize();
        })->save();

        if (Storage::disk('s3')->put('/uploads/partners/logos/'. $filename, fopen($path, 'r+'))) {
            \File::delete($path);
        }
        $partner->logo_filename = $filename;
        $partner->save();
    }
rin4ik's avatar

you can't redirect to post route. create get route to redirect. or redirect to existing route

kendrick's avatar

Sorry, meant the get Route, the redirect still fails @rin4ik

How can I see if the Job works? I run php artisan queue:work but nothing will be corresponded to the queues table..

Also restarted php artisan queue:restart

rin4ik's avatar

you want your images stored in db? did you create jobs table?

kendrick's avatar

Yes jobs table was created. No images should be stored locally first, then the Job will be dispatched to store it long-term within s3 and the the local file will be deleted. You showed me how to manage it @rin4ik

kendrick's avatar

Yes @rin4ik

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class UploadLogo implements ShouldQueue

Default queue connection name is


    'default' => env('QUEUE_DRIVER', 'sync'),

Should it be database?

rin4ik's avatar

of course set it in .env

QUEUE_DRIVER=database

it will never save job to db if you don't set queue driver to database.!

kendrick's avatar

Somehow it won't save the file to s3 and delete the local (storage) file.

$path = storage_path() . '/uploads/' . $this->fileId . '.png';
$filename = $this->fileId . '.png';

        Image::make($path)->fit(250, 250, function ($c) {
            $c->upsize();
        })->save();

if (Storage::disk('s3')->put('/uploads/partners/logos/'. $filename, fopen($path, 'r+'))) {
            \File::delete($path);
}

Is there a way to see where the file gets lost?

rin4ik's avatar
rin4ik
Best Answer
Level 50
if (Storage::disk('s3')->put('/uploads/partners/logos/'. $filename, fopen($path, 'r+'))) {
            \File::delete($path);
}

this line means if this file uploaded to s3 then delete the file. it should be there /uploads/partners/logos/just refresh s3 bucket. and also don't forget run worker

php artisan queue:work
kendrick's avatar

Ah now I see the workflow with Jobs. @rin4ik

After running queue:work it processed the Job, but failed.

Exception

ModelNotFoundException: No query results for model App\Models\Partner
rin4ik's avatar

I can't say anything here without your code . something wrong here with your partner model.

rin4ik's avatar

nope. show me how you dispatch the job in your controller

kendrick's avatar
public function uploadLogo(Request $request, Partner $partner){

            $this->validate($request, [ 
                'logo' => 'required|mimes:jpg,jpeg,png,bmp|max:800',
                'logo.required' => 'Please upload an image',
                'logo.mimes' => 'Only jpeg,png and bmp images are allowed',
                'logo.max' => 'Sorry! Maximum allowed size for an image is 20MB'
            ]);


            if($request->hasFile('logo')){
            if ($request->file('logo')->isValid()) {
                    $request->file('logo')->move(
                    storage_path() . '/uploads',
                    $fileId =  uniqid(true) . '.png'
                  );
                  
                  $this->dispatch(new UploadLogo($partner, $fileId));
            }
            }

            return redirect()
                    ->route('partner.profile.logo')
                    ->with('info', 'Your logo has been uploaded.'); 
     
        }   

Thank you @rin4ik

rin4ik's avatar

and now show UploadLogo job with all data. you are welcome. you now what to do after I solve your problem ;)

kendrick's avatar
use App\Models\Partner;
use Image;
use File;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class UploadLogo implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;


    public $fileId;
    public $partner;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(Partner $partner, $fileId)
    {
        $this->partner = $partner;
        $this->fileId = $fileId;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $path = storage_path() . '/uploads/' . $this->fileId . '.png';
        $filename = $this->fileId . '.png';

        Image::make($path)->fit(250, 250, function ($c) {
            $c->upsize();
        })->save(); 

        if (Storage::disk('s3')->put('/uploads/partners/logos/'. $filename, fopen($path, 'r+'))) {
            \File::delete($path);
        }
 
        $partner->logo_filename = $filename;
        $partner->save();
    }
}
rin4ik's avatar

I think Partner $partner is empty. are you updating partner logo right?

rin4ik's avatar

dd($partner) please in your controller. what you get?

kendrick's avatar

Returns the fillable array but empty so only lists the possible columns, should I add $partner = Auth::user(); @rin4ik

rin4ik's avatar

show me partner model. maybe you have changed getRoutKeyName in your model? before it worked? show me your route for upload logo as well please

kendrick's avatar

Partner.php


use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Auth\Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;

class Partner extends Model implements AuthenticatableContract, CanResetPasswordContract
{
    use Authenticatable, CanResetPassword, Notifiable;

    protected $guard = 'partner';
    
    protected $table = 'partners';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'first_name', 'last_name', 'email', 'password', 'name', 'email_token', 'logo_filename'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

Route

Route::get('partner.profile.logo', [
    'uses' => 'PartnerProfileController@getPartnerLogo', 
    'as' => 'partner.profile.logo',
    'middleware' => ['auth:partner'],
    ]);

Route::post('partner.profile.logo', [
    'uses' => 'PartnerProfileController@uploadLogo', 
    'middleware' => ['auth:partner'],
    ]);
rin4ik's avatar

what url u have when you go to upload logo in browser ? I don't really understand this kinda route setups.

kendrick's avatar
<form enctype="multipart/form-data" action="{{route('partner.profile.logo')}}" method="POST">

@rin4ik

rin4ik's avatar

u are not passing partner that's your problem. when you go to browser partner page what's the url. localhost:8000/partner/profile/logo or what?

kendrick's avatar
it is /partner/{partnername}

@rin4ik

When I try

if($request->hasFile('logo')){
            if ($request->file('logo')->isValid()) {
                    $request->file('logo')->move(
                    storage_path() . '/uploads',
                    $fileId =  uniqid(true) . '.png',

                    $partner = Auth::user(),
                    $partner->logo_filename = $fileId,
                    $partner->save()
                  );
                  
                  $this->dispatch(new UploadLogo($partner, $fileId));
            }
            }

it will process jobs until 262 tries...

Next

Please or to participate in this conversation.