I'm having a hard time to read multiple file paths from my product tables in laravel.
I'm using Voyager as my admin interface, I have a multiple file upload that saves my path image in a field, when i query the table i get these result:
how do i read the photo field?
Already tried: json_decode($product->photo,true) and it says "htmlspecialchars() expects parameter 1 to be string, array given"
with @foreach ($product->photo as $img) it gives me "Invalid argument supplied for foreach() "
CodePudding user response:
photo column must be defined as JSON in its migrations file.
$table->json('photo');
And cast it to array in Product Model class:
protected $casts = [
"photo" => "array"
];
Now you will access photo as array and do what you want.