amk
1 year ago

Multiple image upload and Insert into multiple row of database...

Posted 1 year ago by amk

I want to upload multiple image but I don't want to insert image name in only one row of database. When I upload 4 photos,database must have 4 rows. Anyone can suggest me,how to fix this pls... IDK how to create multiple row of database from controller...

public function store(Request $request)
    {
        $files = $request->file('file');
     foreach ($files as $file) {
         $filename = uniqid() . '_' . $file->getClientOriginalName();
         $file->move(public_path('/images/products'),$filename);
    }

     Media::create([
    
    ??????????
        
    ]);
     return redirect()->route('media.index');

 }

That's from my view..

<form id="target" method="post" action="{{route('media.store')}}" enctype="multipart/form-data">
     {{ csrf_field() }}
    <input type="file" name="file[]" id='fil' multiple> 
</form>
 
   <script>
  $(document).ready(function(){
  $('#fil').change(function() {
  $('#target').submit();
});
});
  </script>

Please sign in or create an account to participate in this conversation.