mercredi 6 juin 2018

How to get id When Using Implicit Route Model Binding, i need it in unique validation

// in the validation section "alias" field should be unique so i need this NursingHome object id(primary key) to force validation to not to check for this id, i have check it with $nursinghome->getKey() method but no success

public function update(Request $request, NursingHome $nursinghome)
{
 $request->validate([
   'name' => 'required|string|max:255',
   'address' => 'nullable|string',
   'alias' => 'required|string|unique:nursing_home,'.$nursinghome->id,

]);

    $data = $request->all();
    $data['updated_by'] = Auth::guard('api')->id();
    $nursinghome->update($data);

    return response()->json($nursinghome, 200);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire