php - Proper use of updateOrCreate method -
i have onetoone relationship between insurances table , confirmations table.
here migration confirmations:
$table->increments('id'); $table->integer('insurance_id')->unsigned()->index()->unique(); $table->boolean('status'); $table->timestamps(); $table->foreign('insurance_id')->references('insurancenumber')->on('insurances');
i want make status updatable.
there form 2 buttons of reject , accept , controller this:
public function confirmation(){ $confirm_button = request::get('confirm_button'); $reject_button = request::get('reject_button'); if (isset($confirm_button)){ $status = true; }else if (isset($reject_button)){ $status = false; } confirmation::updateorcreate(['insurance_id' => session('insurance_id')],['status'=> $status]); } }
i want if confirmations row same insurance_id exists, update it.
it setting false on status. session has right value, checked before.
if want prevent duplicate entry check unique attribute using unique validation rules.
or, can first check in database using find or query builder , create new instance of model if it's not exist.
$status variable never reaches else block. may need post form code deeper investigation.
Comments
Post a Comment