Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

John_Christian's avatar

I Can't save my picture to my directory. I am saving my data in database at the same time sending mail. this is my latest code but not working in saving images to directory. i want to save $front_licens & $back_license to my directory.

public function booking_submit(Request $request, $id) { $car_details = AddCar::find($id);

// Get the file data
$front_license = $request->file('front_license');
$back_license = $request->file('back_license');

 $data = [
    'name' => $request->name,
    'con_num' => $request->con_num,
    'address' => $request->address,
    'con_email' => $request->con_email,

    'front_license' => $request->front_license,
    'back_license' => $request->back_license,

    'mode_del' => $request->mode_del,

    'payment' => $request->payment,

    'start_date' => $request->start_date,
    'start_time' => $request->start_time,
    'return_date' => $request->return_date,
    'return_time' => $request->return_time,

    'msg' => $request->msg,

    'car_details' => $car_details,
  ];

  $data['car_id'] = $car_details->id;

  
// Save data to database
  $booking = new Booking;
  $booking->name = $data['name'];
  $booking->con_num = $data['con_num'];
  $booking->address = $data['address'];
  $booking->con_email = $data['con_email'];

  $booking->front_license = $data['front_license'];
  $booking->back_license  = $data['back_license'];

  $booking->mode_del = $data['mode_del'];
  $booking->payment = $data['payment'];
  $booking->start_date = $data['start_date'];
  $booking->start_time = $data['start_time'];
  $booking->return_date = $data['return_date'];
  $booking->return_time = $data['return_time'];
  $booking->msg = $data['msg'];
  $booking->car_id = $data['car_id'];

if ($front_license) {
  $front_license_name = time() . '_' . $front_license->getClientOriginalName();
  $front_license->move('images/license/front/', $front_license_name);
  $booking->front_license = $front_license_name;

}

if ($back_license) { $back_license_name = time() . '_' . $back_license->getClientOriginalName(); $back_license->move('images/license/back/', $back_license_name); $booking->back_license = $back_license_name; }

  $booking->save();

  Mail::send('main.email-template', ['data' => $data], function($message) use ($data) {
    $message->to('[email protected]');
    $message->subject('Daily Booking Form');
});
0 likes
2 replies
LaryAI's avatar
Level 58

It looks like you are missing the $booking->save() call after you set the $booking->front_license and $booking->back_license values. Try adding the following code after you set the license values:

$booking->save();

Also, make sure that the directory you are trying to save the images to has the correct permissions set.

Please or to participate in this conversation.