I'm learning Laravel right now on Laravel From Scratch 2022 by Traversy Media (Youtube). I want to create a file upload function for new listing form. When I tried to upload, the image was uploaded into the right path in public storage but the path is not in the database, instead the value inserted is 0.
Here is the code for ListingController.php
// Store Listing Data
public function store(Request $request) {
$formFields = $request->validate([
'title' => 'required',
'company' => ['required', Rule::unique('listings','company')],
'location' => 'required',
'website' => 'required',
'email' => ['required', 'email'],
'tags' => 'required',
'description' => 'required'
]);
$directory = "logos";
if($request->hasFile('logo')) {
$formFields['logo'] = $request->file('logo')->store('logos','public');
}
Listing::create($formFields);
return redirect('/')->with('message', 'Listing created successfully!');
}
Here is the screenshot of image that I successfully uploaded but the value in database is 0.
Screenshot of Laravel storage/app/public/logos directory
Screenshot of MySQL database, column logo is used to store image path
Thank you for your help!
$requesthas a file present in it?logoin your database is a string/varchar?$request->file('logo')->store('logos','public')?