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.');
}
public function uploadLogo(Request $request){
$partner = Partner::whereId(auth()->id())->findOrFail();
will result in:
Too few arguments to function Illuminate\Database\Eloquent\Builder::findOrFail()
$partner = Partner::where('user_id', auth()->id())->get();
Still zero passed at least one expected at findOrFail(); :/ @rin4ik
$partner = Partner::where('user_id', auth()->id())->get();
dd($partner). I don't understand which loop
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));
I think you can just pass $partner does it work now correctly ?
No, after running queue:work, it processes again UploadLogo up to 255 times without failing or uploading anything :/ Thank you for your patience @rin4ik
@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));
}
}
Yes, now:
Method Illuminate\Database\Eloquent\Collection::save does not exist.
try with just first()
$partner = Partner::where('user_id', auth()->id())->first();
Already tried it.
Again the 255 attempts @rin4ik
in your upload logo job you save to s3 not to db. you know about it? check s3 now
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.
now you have that file in your storage folder?
Yes. This works. So the files are always moved within storage.
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
Again it attempts to upload the file within 255 attempts, also the s3 folder tries to refresh automatically without failing. @rin4ik
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.
@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.
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
@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
Please sign in or create an account to participate in this conversation.