I have a field in my AppSetup table called reference_images
that is added as follows in the migration: $table->json('reference_images')->nullable();
and casted as an array in the AppSetup model. I have a method that adds image urls to the database. If it's for the reference_image
field, I am trying to push it to the array but I keep getting an "Array to String conversion" error in Laravel.
public function addImagesToAppSetup($imageType=null, $image=null)
{
$appSetup = AppSetup::where('store', '=', id())->first();
if ($image) {
if ($imageType == "reference_images") {
$originalArray = $appSetup->$imageType;
$originalArray[] = $image;
$appSetup->$imageType = array_values(array_unique($originalArray));
} else {
$appSetup->$imageType = $image;
}
}
$appSetup->save();
return response()->json(['status' => 1, 'data' => $appSetup]);
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Tz7vk0
via IFTTT
Aucun commentaire:
Enregistrer un commentaire