我已经将图像存储在阵列中,现在我试图在刀片模板中显示图像

时间:2020-08-14 18:46:36

标签: php mysql laravel laravel-7.x

刀片文件

<div class="col-md1 simpleCart_shelfItem">
    <a href="single.html">
        @foreach(explode('|', $product->image) as $image))
        <img class="img-responsive" src="{{url('/uploads'.'/'.$product->image)}}" alt="" />
        @endforeach
    </a>
    <h3><a href="single.html">{{$products->name}}</a></h3>
    <div class="price">
        <h5 class="item_price">{{$products->price}}</h5>
        <a href="#" class="item_add">Add To Cart</a>
        <div class="clearfix"> </div>
    </div>
</div>

产品负责人

public function store(Request $request){

        //validate the form 
        $request->validate([
            'name'=>'required',
            'price'=>'required',
            'description'=>'required',
            'categories'=>'required',
            'image'=>['required:image']
        ]);

        //upload the image

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

型号

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $guarded=[];
    

    public function subcategory(){

        return $this->hasMany('App\Product', 'categories');
    }
}

0 个答案:

没有答案