0

I changed the image upload directory to the public folder, but why is the file uploaded to the database on the tmp path? I want the record name in the database to match the file name. Can anyone help?

Controller (store method)

public function store(Request $request)
{
    $validatedData = $request->validate([
        'banner_title' => 'required|max:255',
        'image' => 'image|file|max:5120',
    ]);

    $imageName = time() . '.' . $request->image->extension();
    $request->image->move(public_path('images/banner-image'), $imageName);

    Banner::create($validatedData);

    return redirect('/dashboard/banner')->with('msg', 'Success!');
}
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
Ana
  • 1

1 Answers1

0

Here is the solution,

  • Add below statement before the Banner::create($validatedData);

$validatedData['image'] = $imageName;

  • In here we can assign validated image to $imageName after that we can save it in database.
Pathum Bandara
  • 343
  • 2
  • 3
  • 12