Level 5
I would avoid using request->all() and specify each field on its own:
$result->create([
'field1' => $request->field1,
'field2' => $request->field2,
...
'user_id' => 1,
'image' => $file->getClientOriginalName()
])
Hi,
I'm trying to upload a file to disk and store the image filename in the database.
It is uploading to disk OK, but keeps writing xampp\tmp\php3985.tmp to the database field 'image'.
I attempted to use $request->offsetUnset('image'); to try to exclude this from the the request->all and set it myself, but that didn't appear to work.
Any help much appreciated.
Thanks,
// upload
$file = $request->file('image');
$file->move(public_path().'/images/',$file->getClientOriginalName());
// set in db
$result = new CollectionItem;
$request->offsetUnset('image');
$result->create($request->all() + [
'user_id' => '1',
'image' => $file->getClientOriginalName()
]);
I would avoid using request->all() and specify each field on its own:
$result->create([
'field1' => $request->field1,
'field2' => $request->field2,
...
'user_id' => 1,
'image' => $file->getClientOriginalName()
])
Please or to participate in this conversation.