samedi 29 juin 2019

Undefined property: stdClass::$images

In products table I have image row which stores images of every product and looks like this in database ["4.jpg","5.jpg"] in each product. Now I want to display the product and the images which belongs to that product in the view but am stuck it shows an error Undefined property: stdClass::$images how can I fix this ?

Here are the codes

blade view

   @foreach($products as $product)
   @foreach($product->images as $image)
      <img src="" alt="">
     @endforeach
     @endforeach

Controller

public function store(Request $request) 
{ 

$Input=$request->all();
$image=array();
if($files=$request->file('image')){
    foreach($files as $file){
        $name=$file->getClientOriginalName();
        $file->move('images',$name);
        $image[]=$name;

    }

} 
 product::create(array_merge($Input,
 [
'image' => json_encode($image),

])); 
return redirect()->back(); 

}

Any help will be appriciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire