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

mohammadkhallaf's avatar

The customer id field is required

controller

 public function update(Request $request, $id)
    {
        $appointment = Appointment::findOrFail($id);
        try {
            $request->validate([
                'customer_id' => 'required|exists:customers,personal_id',
                'date' => 'required|date',
                'clinic' => 'required|string',
                'physician' => 'required|string',
                'name' => 'required|string',

            ]);

            $appointment->update([
                'customer_id' => Customer::where('personal_id', $request->customer_id)->first()->id,
                'date' => $request->date,
                'note' => $request->note,
                'clinic' => $request->clinic,
                'physician' => $request->physician,
                'name' => $request->name
            ]);
            return redirect()->route('admin.appointment')->with(['success' => 'تم ألتحديث بنجاح']);
        } catch (Exception $ex) {

            return $ex;
            return redirect()->route('admin.appointment')->with(['error' => 'هذا الموعد غير موجود ']);
        }
    }

blade

 <div class="row">
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <label for="projectinput1">رقم الهوية </label>
                                                            <input type="text" value="{{$appoin->customer->personal_id}}" id="customer_id"
                                                                class="form-control" name="personal_id">
                                                            @error('personal_id')
                                                                <span class="text-danger">{{ $message }}</span>
                                                            @enderror
                                                        </div>
                                                    </div>

0 likes
7 replies
navneet's avatar
<input
        type="text"
        value="{{$appoin->customer->personal_id}}"
        id="customer_id"
        class="form-control"
        name="customer_id"
      />

Change name="personal_id" to name="customer_id"

mohammadkhallaf's avatar

@navneet

array:9 [▼ // app\Http\Controllers\AppointmentController.php:114
  "_token" => "fjQBIvUVLmNOFC7J2zDyESPGv2ZiGcS24ROuGE0g"
  "_method" => "PUT"
  "customer_id" => "12345678"
  "name" => "mohammadkhallaf"
  "date" => "2022-12-13"
  "hour" => "12:47:00"
  "clinic" => "sd"
  "physician" => "sad"
  "note" => "dsfsdfd"
]
tykus's avatar
tykus
Best Answer
Level 104

@mohammadkhallaf the error must be different if you have changed the field name to customer_id?

Aside, this is unnecessary; you have already established from the validation rules that the ID is valid!

$appointment->update([
    'customer_id' => Customer::where('personal_id', $request->customer_id)->first()->id,
navneet's avatar

@mohammadkhallaf Does the customer_id actually exist in the customers table? validation is failed because personal_id does not matches the id from blade input.

1 like
tykus's avatar

@navneet the required validation was the original failure; so it was not in the Request (as you identified above); therefore the error must be different as the OP has now received a customer_id

1 like

Please or to participate in this conversation.