Skip to content
Advertisement

How to insert 3 image to 3 field in DB Laravel

I want to insert 3 images to 3 fields in DB, but I can’t move this to folder public. My code in function store in Controller

   $room =  Room::create([
        'img1' =>  $request->img1 ,
        'img2' =>$request->img2,
        'img3' =>$request->img3,
        ...
    ]);
    $room->save();
    if ($request->hasFile('img1')) {
        $request->img1->move(public_path('images/rooms'), $request->img1);
    } 
    if ($request->hasFile('img2')) {
        $request->img2->move(public_path('images/rooms'), $request->img2);
    }
    if ($request->hasFile('img3')) {
        $request->img3->move(public_path('images/rooms'), $request->img3);
    }

Someone help me. Thank you.

Advertisement

Answer

Try this:

use IlluminateSupportFacadesStorage;

if ($request->hasFile('img1') {
  Storage::put('images/rooms', $request->img1);
}
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement