Support the ongoing development of Laravel.io →
Input Eloquent Forms

Hi,

I'm using mass-assignment to insert a load of records into the database, how do I handle a file upload with the procedure?

Do I grab the file upload from the POST array, upload it to my chosen path and assign the location value back to the array that's passed to the mass-assignment, or is there a better way?

Thanks

Last updated 3 years ago.
0

Pretty much how you described, but don't use POST array, use Request's methods.

$uploadedFile = $request->file('myfile');
$uploadedFile->move('directory/for/files/', 'filename.ext');

$uploadedFile is an object of Symfony\Component\HttpFoundation\File\UploadedFile class, it has some useful function for getting file name, extension, type.

0

Great, thank you.

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.