Laravel's Uploaded File loses properties while passing between methods - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Sunday, July 30, 2023

Laravel's Uploaded File loses properties while passing between methods

In my controller's method I call my service to store images.

MediaService::storeImages($pa, $r->images, $r->main_image);

FileService.php

public static function storeImages($pa, $images, $mainImageName)
{
    dd(1, $mainImage);

    MediaService::addMediaToCollection($pa, $mainImage);
}

public static function addMediaToCollection($model, &$medium, $collection = null)
{
    dd(2, $medium);
}

First dump and die looks like this:

Correct file

But the second one turns into this, losing its attributes: lost attributes

I tried adding and removing & to accept the pointer instead of copy but it didn't help.

I know I could create instance of this class and have the image as a variable accessible by all the methods, but its beyond my question, which is - why this occurs and how to stop it?

Thank you.



source https://stackoverflow.com/questions/76794645/laravels-uploaded-file-loses-properties-while-passing-between-methods

No comments:

Post a Comment