Sep 10, 2018
0
Level 1
Get the location for uploaded files (storage path + hashed file name + extention)
I have an upload where images can be uploaded. I have 2 fields dedicated for the image(which is a logo) logo and original_filename.
Right now when I upload only the original_filename seems to work. The other one takes the temp location and places the following in the database: C:\xampp\tmp\phpF3EC.tmp Which of course is not what I want to happen. I want this to be carrier_logo/ZbCG0lnDkUiN690KEFpLrNcn2exPTB8mUdFDwAKN.png for example.
Here is my controller function:
public function store(Request $request)
{
request()->validate([
'name' => 'required',
'logo' => 'nullable',
'original_filename' => 'nullable',
]);
//This is where the file uploads?
if ($request->hasFile('logo')) {
//Get location, doesn't work now.
$path = $request->file('logo')->store('carrier_logo');
//Get original name
$original_filename = $request->file('logo')->getClientOriginalName();
//Add to request
$request->merge([
'logo' => $path,
'original_filename' => $original_filename,
]);
}
Carrier::create($request->all());
return redirect()->route('carriers.index')->with('toast', 'Carrier created successfully.');
}
Please or to participate in this conversation.