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

rin4ik's avatar

one option for this problem will be:

public function uploadLogo(Request $request){

    $partner = Partner::whereId(auth()->id())->findOrFail();
             $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.'); 
     
        }   
kendrick's avatar
public function uploadLogo(Request $request){

            $partner = Partner::whereId(auth()->id())->findOrFail();

will result in:

Too few arguments to function Illuminate\Database\Eloquent\Builder::findOrFail()

rin4ik's avatar
  $partner = Partner::where('user_id', auth()->id())->get();
rin4ik's avatar
  $partner = Partner::where('user_id', auth()->id())->get();
rin4ik's avatar

dd($partner). I don't understand which loop

kendrick's avatar

After running php artisan queue:work it processes the UploadLogo Job up to 255 times without failing.

Now it gets the attributes of the Partner. @rin4ik

Do I need to adjust this line ?

$this->dispatch(new UploadLogo($partner, $fileId));

into

$this->dispatch(new UploadLogo(Partner $partner, $fileId));
rin4ik's avatar

I think you can just pass $partner does it work now correctly ?

kendrick's avatar

No, after running queue:work, it processes again UploadLogo up to 255 times without failing or uploading anything :/ Thank you for your patience @rin4ik

rin4ik's avatar

@splendidkeen

if($request->hasFile('logo')){
            if ($request->file('logo')->isValid()) {
                    $request->file('logo')->move(
                    storage_path() . '/uploads',
                    $fileId =  uniqid(true) . '.png'
 );
                   $partner = Partner::where('user_id', auth()->id())->get();
                    $partner->logo_filename = $fileId;
                    $partner->save();
                 
                  
                  $this->dispatch(new UploadLogo($partner, $fileId));
            }
            }
kendrick's avatar

Yes, now:

Method Illuminate\Database\Eloquent\Collection::save does not exist.
rin4ik's avatar

try with just first()

$partner = Partner::where('user_id', auth()->id())->first();
rin4ik's avatar

in your upload logo job you save to s3 not to db. you know about it? check s3 now

kendrick's avatar

Yes I know.

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

Always checking if something was uploaded within the folder.

rin4ik's avatar

now you have that file in your storage folder?

kendrick's avatar

Yes. This works. So the files are always moved within storage.

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

delete this line and try again. also dd($product) in your UploadJob please

kendrick's avatar

Again it attempts to upload the file within 255 attempts, also the s3 folder tries to refresh automatically without failing. @rin4ik

kendrick's avatar

I tried an upload before without a Job.

if($request->hasFile('logo')){

            $partner = Auth::user();

            $image   = $request->file('logo');
            $filename = time() . '.' . $image->getClientOriginalExtension();

            Image::make($image)->resize(300,300);
            $s3 = Storage::disk('s3')->put('/uploads/partners/logos/', $request->file('logo'), 'public');
             
            
            
            $partner->logo_filename = $filename;
            $partner->save();
 
        }

and it worked.

rin4ik's avatar

@splendidkeen you can leave it like that with. with jobs you are doing something exactly wrong . It will not take much time to upload logo.

kendrick's avatar

Ok, but somehow I will try to manage to get it work with Job because its better in terms of scaling and error handling etc. @rin4ik

Thank you again

rin4ik's avatar

@splendidkeen play around with your job and try to figure out what's wrong . I'm sure you can manage.always our discussion leader in Popular This Week section:) I'd like to help you with that but it's really hard to guess without seeing your code in real. when you solve this issue please notify me I wanna know what's wrong

1 like
Previous

Please or to participate in this conversation.