Fadl94's avatar
Level 16

How to Upload images use Queues Request From Postman(API)

Error Serialization of 'Illuminate\Http\UploadedFile' is not allowed

################################ Contaroller : dispatch(new UploadImages($data->images,$property_id));

########################### class UploadImages implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public $data;
public $property_id;
public function __construct($data,$property_id)
{
    $this->data = $data;
    $this->property_id = $property_id;
}


public function handle()
{ 
 
    logger($this->data);
    foreach ($this->data as $image) {
        DB::table('medias')->insert(
            [
                'file' => upload('Properties', $image),
                'mediable_id' => $this->property_id,
                'mediable_type' => 'App\Models\Property'
            ]
        );
    
    }
}
0 likes
5 replies
Fadl94's avatar
Level 16

upload() helper function i made to upload image

/**

  • Upload */ if (! function_exists('upload')) { function upload($file, $path) { $baseDir = 'uploads/'.$path;

     $name = sha1(time() . $file->getClientOriginalName());
     $extension = $file->getClientOriginalExtension();
     $fileName = "{$name}.{$extension}";
    
     $file->move(public_path().'/'.$baseDir, $fileName);
    
     return "{$baseDir}/{$fileName}";
    

    } }

Please or to participate in this conversation.