php - Why is laravel's updateOrCreate creating new records instead of updating? -


code

entry::updateorcreate([     'intern_id'=>$intern['id'],     'created_at'=>carbon::parse($input['date'])     ],[     'company_id'=>$intern['supervisor']['company']['id'],     'content'=>$input['text'] ]); 

i'm using code try updating/creating new record. it's suppose matche intern_id , create_at column first. if found, creates new one. however, seems creating new 1 , when creates new one, company_id , intern_id column set 0 instead of original value.

note: intern_id or created_at not pk columns. note2: created_at date type, not datetime

use code

entry::updateorcreate(['intern_id'=>$intern['id']],     [         'created_at'=>carbon::parse($input['date']),         'company_id'=> $intern['supervisor']['company']['id'],         'content'=>$input['text']     ]); 

i believe work.

updateorcreate() function of model abstract class takes 2 parameters, parameter passing breaking.

/**      * create or update record matching attributes, , fill values.      *      * @param  array  $attributes      * @param  array  $values      * @return static      */     public static function updateorcreate(array $attributes, array $values = array())     {         $instance = static::firstornew($attributes);          $instance->fill($values)->save();          return $instance;     } 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -