// Upload directory for profile image $directory = __DIR__ . '/../../../public/category_image'; //removed @ from #@request $uploadedFiles = $request->getUploadedFiles()['category_image']; //$avater = []; $avater = $request->getUploadedFiles(); foreach($uploadedFiles as $uploadedFile) { if (@$uploadedFile->getError() === UPLOAD_ERR_OK) { $avater = \App\Helpers\FileUpload::moveUploadedFile($directory, $uploadedFile, ['png', 'jpeg', 'gif', 'jpg']); } else { //(new Flash)->addMessage('message', "Sorry, something went wrong from our end, please notify site owner"); $Flash = new Flash(); $Flash->addMessage('message', "Sorry, something went wrong from our end, please notify site owner"); $Flash->addMessage('status', "callout-danger"); return $response->withRedirect($this->router->pathFor('users')); } } if( ! $avater ) { //(new Flash)->addMessage('message', "Sorry, Please make image you are uploading is either a 'png', 'jpeg', 'gif' or 'jpg'"); $Flash = new Flash(); $Flash->addMessage('message', "Sorry, Please make image you are uploading is either a 'png', 'jpeg' or 'gif'"); $Flash->addMessage('status', "callout-danger"); return $response->withRedirect($this->router->pathFor('car_description')); } $car_description = CarDescription::create([ 'car_category_id' => $car_category_id, 'name' => $name, 'description' => $description, 'year' => $year, 'mileage' => $mileage, 'price' => $price, 'fuel_type' => $fuel_type, 'transmission' => $transmission, 'fuel_economy' => $fuel_economy, 'air_condition' => $air_condition, 'hourly_price' => $hourly_price, 'daily_price' => $daily_price, 'images' => json_encode($avater) ]);
the code above is to add an image to a description, but it stores image like as a json instead of image.jpg
{“car_images”:[{“file”:“C:\Users\rmumo\AppData\Local\Temp\phpB18.tmp”}]}
what am i doing wrong?