@hal.littel
To upload multiple files in a database using Laravel, you can follow these steps:
Here is an example of how you can achieve this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// Controller method to handle file uploads public function uploadFiles(Request $request) { $files = $request->file('files'); foreach ($files as $file) { $filename = $file->getClientOriginalName(); $file->store('uploads'); // Save the file to the storage directory // Save the file path and filename in the database File::create([ 'filename' => $filename, 'filepath' => 'storage/uploads/' . $filename ]); } return redirect()->back()->with('message', 'Files uploaded successfully'); } |
Make sure to create a File
model to interact with the database table where you will store the file information. Also, don't forget to set up the storage directory in your Laravel application to store the uploaded files.
With these steps, you should be able to upload multiple files to your database using Laravel.