Я пытаюсь понять, как обновить и модальный Eloquent ORM из массива. Вместо того, чтобы идти поле за полем. Это то, что у меня есть до сих пор.
public static function updatePatient($id){
$patient_payload = Input::all(); // eg. array('patient_first_name'=>'Test', 'patient_last_name'=>'TEST')
$patient_to_update = Patient::find($id);
/*
|--------------------------------------------------------------------------
| Validate the request
|--------------------------------------------------------------------------
*/
if(!$patient_to_update)
return Response::json(array('error'=>'No patient found for id given'), 400);
/*
|--------------------------------------------------------------------------
| Update the patient entry.
|--------------------------------------------------------------------------
*/
$patient_to_update->update($patient_payload);
$patient_to_update->save();
return Response::json(array('success'=>'Patient was updated'));
}
Это выдает ошибку модели laravel, просто говоря: «patient_first_name» и да, «терпеливое_первое_имя» — это столбец в базе данных. В качестве обходного пути я только что делал это, и это работает.
public static function updatePatient($id){
$patient_payload = Input::all();
$patient_to_update = Patient::find($id);
/*
|--------------------------------------------------------------------------
| Validate the request
|--------------------------------------------------------------------------
*/
if(!$patient_to_update)
return Response::json(array('error'=>'No patient found for id given'), 400);
/*
|--------------------------------------------------------------------------
| Update the patient entry.
|--------------------------------------------------------------------------
*/
DB::table('patients')
->where('id',$id)
->update($patient_payload);
//update laravel timestamps
$patient_to_update->touch();
return Response::json(array('success'=>'Patient was updated'));
}