php - laravel firstOrCreate not working properly? -


i importing data foursquare api. database contains multiple foursquare_id duplicates. doing wrong code here?

i thought way set check database column value of foursquare_id?

bar::firstorcreate([     // not check these 2 below because mandatory     'foursquare_id' => $item['venue']['id'],     'name' => $item['venue']['name'],     'postalcode' => isset($item['venue']['location']['postalcode']) ? $item['venue']['location']['postalcode'] : '',     'city' => isset($item['venue']['location']['city']) ? $item['venue']['location']['city'] : '', ]); 

that's right. receive 'first' if all elements of passed array exist in row object.

the alternative using firstornew:

$foo = bar::firstornew(['foursquare_id' => $item['venue']['id']]); // find object foursquare_id. nothing found? create new 1 given foursquare_id $foo->name = $item['venue']['name']; $foo->postalcode = isset($item['venue']['location']['postalcode']) ? $item['venue']['location']['postalcode'] : ''; $foo->city = isset($item['venue']['location']['city']) ? $item['venue']['location']['city'] : ''; $foo->save(); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -