How to upload multiple images into a database using laravel?

Malik Zubair Mukhtar

I am trying to Upload multiple images into a database but only one is uploading instead of multiple.

How to upload multiple images into a database?

Could anyone tell me what is wrong with my code?

        [database table ][1]
        [1]: https://i.stack.imgur.com/kgv4r.png  

controller

public function singalprojectaction(Request $request)
  {
   $input=$request->all();
   $images=array();
   if($files=$request->file('images')){
   foreach($files as $file){
   $name=$file->getClientOriginalName();
   $file->move(public_path('projects'), $name);
   $images[]=$name;
   }
   }
   $query=DB::table('single_portfolio')->insert( [
  'Project_name' =>$input['project_name'],
  'Client_Name' =>$input['Client_name'],
  'Completion_date' =>$input['Completion_date'],
  'Duration' =>$input['Duration'],
  'project_image_one'=>  implode("|",$images),
  'Description' =>$input['Description'],
   'project_id' =>$input['select_project'],
   ]);
  if($query)
   {
   return response()->json([
  'message'   => 'Image is Successfully Inserted',
  'class_name'  => 'alert-success'
  ]);
   }
  else{

 return response()->json([
'message'   => 'Data  is not inserted Inserted',
'class_name'  => 'alert-warning'
 ]);

  }
  }

html view

<form action="Route('singal.action') }}" id="singal_project" 
   enctype="multipart/form-data">
   {{ csrf_field() }}
   <div class="alert" id="message" style="display:block;"></div>
   <div class="group-form">
      <label>Drop Multple Imges</label>
      <input required type="file" class="form-control" name="images[]"
         multiple>
   </div>
</form>
Vikas Katariya

Try This To insert multiple images

 public function singalprojectaction(Request $request)
  {
     $input=$request->all();
     $datas = [];
     $result = [];
     if ($request->hasfile('images')) {
        foreach ($request->file('images') as $key => $file) {
        $name = $file->getClientOriginalName();
        $file->move(public_path() . '/projects/', $name);
             $datas[$key] = $name;
        }
    }

        $query=DB::table('single_portfolio')->insert( [
                  'Project_name' =>$input['project_name'],
                  'Client_Name' =>$input['Client_name'],
                  'Completion_date' =>$input['Completion_date'],
                  'Duration' =>$input['Duration'],
                  'project_image_one'=>  implode("|",$datas);
                  'Description' =>$input['Description'],
                  'project_id' =>$input['select_project'],
                   ]);
        if($query){
          return response()->json(['message'   => 'Image is Successfully Inserted','class_name'  => 'alert-success']);
                   }
        else{
          return response()->json(['message'   => 'Data  is not inserted Inserted','class_name'  => 'alert-warning'
                 ]);
           }
        }

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to upload multiple images to cloudinary and send urls to another database using javascript

分類Dev

Upload multiple images to Database MYSQLI

分類Dev

How to upload images into MySQL database using PHP code

分類Dev

Upload multiple images using AFNetworking

分類Dev

how do i upload multiple images using Multiparty Entity in Android

分類Dev

Upload multiple images to a database from a singe fileinput

分類Dev

Multiple Image Upload using Ajax with Laravel 5.6

分類Dev

How to upload data to database using codeigniter

分類Dev

How to image upload into databae using laravel?

分類Dev

How to add text to multiple images using Python

分類Dev

How do I save multiple checkbox values in a single column in the database and retrieve it using laravel

分類Dev

how to upload images to ftp server using spring MultipartFile without storing images in local disk

分類Dev

how to upload images to ftp server using spring MultipartFile without storing images in local disk

分類Dev

how to upload images to ftp server using spring MultipartFile without storing images in local disk

分類Dev

Multiple images not showing from database

分類Dev

laravel doesn't upload images on server

分類Dev

FileNotFoundException when upload multiple images to FTP server

分類Dev

Querying Relationship Existence using multiple MySQL database connections in Laravel 5.2

分類Dev

How to Upload multiple files to a server using UnityWebRequest.Post();

分類Dev

How can I upload multiple files using JavaScript and FastAPI?

分類Dev

How to stitch multiple images that are in a random order using OpenCV in python?

分類Dev

File upload using foreach in Laravel

分類Dev

Multiple File Upload using array

分類Dev

How do I get iPads to upload images?

分類Dev

Laravel - multiple selection and saving to database

分類Dev

Laravel Multiple Image Upload via API

分類Dev

How to store emoji string in Database using Laravel with Orm Query

分類Dev

How to load multiple js files to database using mongo shell?

分類Dev

How to insert the multiple row values of a table into the database using php

Related 関連記事

  1. 1

    How to upload multiple images to cloudinary and send urls to another database using javascript

  2. 2

    Upload multiple images to Database MYSQLI

  3. 3

    How to upload images into MySQL database using PHP code

  4. 4

    Upload multiple images using AFNetworking

  5. 5

    how do i upload multiple images using Multiparty Entity in Android

  6. 6

    Upload multiple images to a database from a singe fileinput

  7. 7

    Multiple Image Upload using Ajax with Laravel 5.6

  8. 8

    How to upload data to database using codeigniter

  9. 9

    How to image upload into databae using laravel?

  10. 10

    How to add text to multiple images using Python

  11. 11

    How do I save multiple checkbox values in a single column in the database and retrieve it using laravel

  12. 12

    how to upload images to ftp server using spring MultipartFile without storing images in local disk

  13. 13

    how to upload images to ftp server using spring MultipartFile without storing images in local disk

  14. 14

    how to upload images to ftp server using spring MultipartFile without storing images in local disk

  15. 15

    Multiple images not showing from database

  16. 16

    laravel doesn't upload images on server

  17. 17

    FileNotFoundException when upload multiple images to FTP server

  18. 18

    Querying Relationship Existence using multiple MySQL database connections in Laravel 5.2

  19. 19

    How to Upload multiple files to a server using UnityWebRequest.Post();

  20. 20

    How can I upload multiple files using JavaScript and FastAPI?

  21. 21

    How to stitch multiple images that are in a random order using OpenCV in python?

  22. 22

    File upload using foreach in Laravel

  23. 23

    Multiple File Upload using array

  24. 24

    How do I get iPads to upload images?

  25. 25

    Laravel - multiple selection and saving to database

  26. 26

    Laravel Multiple Image Upload via API

  27. 27

    How to store emoji string in Database using Laravel with Orm Query

  28. 28

    How to load multiple js files to database using mongo shell?

  29. 29

    How to insert the multiple row values of a table into the database using php

ホットタグ

アーカイブ