I have a problem in my project which should merge a file with 'Request',i just find that we can use the function of merge to merge the attributes,but how can we merge a file in laravel?thanks so much.
We can use 'merge' to merge some attributes
$request->merge([
'ticket_id' => '123',
]);
But if i want to merge a file?(i find this way is not workable, i can't not receive a file from the Request)
$request->merge([
'file' => fopen('xxx', 'r'),
]);
And the way likes this is not workable,too.
$request->files = fopen('xxx', '');
You need to create a new UploadedFile and then add the file to the request bag.
$fileAddress = storage_path().'/file.jpg';
$file = new UploadedFile($fileAddress, 'file');
$request->files->set('file', $file);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With