This code isn't saving to the database. Show the code that does
Oct 8, 2022
6
Level 1
How to correct name of upload's image in database?
Have a problem with saving name of poster in database. I want to save files with their own names, not with default. That's why done next construction in my FilmController:
if ($request->hasFile('poster')) {
$poster = $request->file('poster');
$name = $poster->getClientOriginalName();
$poster->storeAs('poster', $name);
}
But in this case name of poster looks like "C:\xampp\tmp\phpBF23.tmp" in database. How to fix it and do, that file will save with it's original name. For example 4563s.jpg
For full description, the code in controller looks so:
/**
* Store a newly created resource in storage.
*
* @param StoreFilmRequest $request
* @return RedirectResponse
*/
public function store(StoreFilmRequest $request): RedirectResponse
{
try {
$film = new Film($request->validated());
if ($request->hasFile('poster')) {
$poster = $request->file('poster');
$name = $poster->getClientOriginalName();
$poster->storeAs('poster', $name);
}
$tags = $film['tags'];
unset($film['tags']);
$film->save();
$film->tags()->sync($tags);
} catch (\Exception $exception) {
abort(404);
}
return redirect(route('admin.films'));
}
Level 102
Try adding (replace image with column name)
$film['image'] = $name;
1 like
Please or to participate in this conversation.