我从来没有过雄辩的保存模型的问题,但是今天这个模型实例不能正常工作。只会抛出这个异常。
Symfony \组件\调试\异常\ FatalThrowableError (E_RECOVERABLE_ERROR)参数1传递给 Illuminate \ Database \ Grammar :: parameterize()必须为数组类型, 给定的字符串,称为 /mnt/c/Desarrollo/displadu/displadu/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php 在第743行
这是雄辩的模型实例
App\Paciente Object (
[table:protected] => paciente
[connection:protected] =>
[primaryKey:protected] => id
[keyType:protected] => int
[incrementing] => 1
[with:protected] => Array
(
)
[withCount:protected] => Array
(
)
[perPage:protected] => 15
[exists] =>
[wasRecentlyCreated] =>
[attributes:protected] => Array
(
[attributes] => Array
(
)
[NOMBRE] =>
[APELLIDOS] =>
[B3_TIPO_AV] => 4
[STATUS_BASAL_pacIdCaso] => 1
[pac_id_ext] => 5b4f24470b2a5
[owner_id] => 2
)
[original:protected] => Array
(
)
[changes:protected] => Array
(
)
[casts:protected] => Array
(
)
[dates:protected] => Array
(
)
[dateFormat:protected] =>
[appends:protected] => Array
(
)
[dispatchesEvents:protected] => Array
(
)
[observables:protected] => Array()
[relations:protected] => Array()
[touches:protected] => Array()
[timestamps] => 1
[hidden:protected] => Array()
[visible:protected] => Array()
[fillable:protected] => Array()
[guarded:protected] => Array(
[0] => *
)
)
控制器上的Action方法,它只调用3个方法,这些方法可以由继承的控制器重新实现。
public function store(Request $request) {
$params = $this->storeVarsInizialization($request);
$params = $this->storeValidateVars($request, $params); // common implementation
return $this->storeVars($request, $params);
}
StoreVarsInizialization只需启动所需的变量即可收集所有所需的信息。
public function storeVarsInizialization(Request $request) {
return array(
'subject' => Session::get('paciente'),
'warnings' => array(),
'warningsChecked' => true
);
}
storeValidateVars使用laravel验证程序并从子控制器调用customValRules来执行所有验证过程,但不进行任何分配,仅存储警告,warningchecked并给出验证程序结果。
控制器方法,此方法只是模板模式的一部分,它是从商店操作方法执行的,该方法仅执行3种专用方法即可从表单运行动态vars
public function storeVars(Request $request, $params) {
$paciente = $params['subject'];
$warnings = $params['warnings'];
$warningsChecked = $params['warningsChecked'];
$validator = $params['validator'];
$completed = $params['completed'];
$user = Auth::user();
log_objectclass(Paciente::class);
log_objectid($paciente->id);
//Hide warning when patient is created
if(isset($paciente->STATUS_BASAL_pacAlta)){ // Se ha guardado info en Alta
// Default:: Show warning
//Do nothing
} else {
// Search and remove warning :: Ingreso hospitalario
unset($warnings['IC6_PACINCL_V0']);
}
if ($validator->fails()) {
log_result(Log::RESULT_FAIL);
return redirect('paciente/'.$this->formName.'/'.$paciente->id)
->withErrors($validator, 'formulario')
->withInput()
//->with('warnings', $warnings)
->with('reload', 'reload');
} else {
if(!empty($warnings) && !$warningsChecked) {
log_result(Log::RESULT_FAIL);
return redirect('paciente/'.$this->formName.'/'.$paciente->id)
->withErrors($validator, 'formulario')
->withInput()
->with('warnings', $warnings)
->with('reload', 'reload');
}
$attr_obj = 'STATUS_BASAL_'.trim($this->formName);
if($completed) {
$paciente->$attr_obj = CODE_STATE_SUCCESS;
} else {
$paciente->$attr_obj = CODE_STATE_PROCESS;
}
unset($paciente->completed);
try {
DB::beginTransaction();
log_result(Log::RESULT_OK);
if($paciente->id > 0){
if (! $user->can('savePaciente', $paciente)) {
log_result(Log::RESULT_DENEGATED);
Session::flash('warning', '<strong>No tienes permisos suficientes para editar este paciente</strong>. Si el error persiste, contacta con el administrador del sistema.');
return redirect('app');
}
if (isset( $paciente->pac_id_ext)) {
// Update
updatePacientInPacientBD($paciente->NOMBRE, $paciente->APELLIDOS, $paciente->pac_id_ext );
} else {
$pac_id = createPacientInPacientBD($paciente->NOMBRE ,$paciente->APELLIDOS);
$paciente->pac_id_ext = $pac_id;
}
$paciente->NOMBRE = '';
$paciente->APELLIDOS = '';
$paciente->update();
$this->postStore($request, false, $params);
}else{
// Create patient on isolated BD
$pac_id = createPacientInPacientBD($paciente->NOMBRE ,$paciente->APELLIDOS);
$paciente->NOMBRE = '';
$paciente->APELLIDOS = '';
if (!isset($pac_id)) {
throw new Exception('No se ha podido crear el paciente en BD externa');
back();
}
$paciente->pac_id_ext = $pac_id;
$paciente->owner_id = $user->id;
$paciente->save();
$this->postStore($request, true, $params);
}
DB::commit();
} catch (Exception $e) {
DB::rollback();
log_result(Log::RESULT_FAIL);
throw $e;
}
if($request->ajax()){
return response()->json(["valid"=>true], 200);
}else{
return redirect('paciente/'.$this->formName.'/'.$paciente->id)
->with('message', 'Formulario enviado correctamente');
}
}
}