I am retrieving JSON from another service and want to insert a bunch of data into the table. I want to make it so that it does not crash every time I run it. I would like to keep my unique restriction for my PC table (because I do not want to insert the same data twice), but I do not want laravel to give a fatal error if this happens (only in a specific table).
How can I insert my data and continue pasting if I try to insert other data with a duplicate primary key?
Schema::create('dummy', function (Blueprint $table) {
$table->integer('id')->unique();
$table->string('name',100);
});
Extract a bunch of JSON from another API. Then insert the whole line:
{
'id':1,
'name': 'one'
},{
'id':2
'name':'two'
}
what is he doing.
DB::table('dummy')->insert([
['id' => 1, 'name' => 'one'],
['id' => 2, 'name' => 'two']
]);
Then the next day, new data about the third-party API appears. And want to update my database:
select json and get:
{
'id':1,
'name': 'one'
},{
'id':2
'name':'two'
},{
'id':3
'name':'three'
}
what is he doing:
DB::table('dummy')->insert([
['id' => 1, 'name' => 'one'],
['id' => 2, 'name' => 'two'],
['id' => 3, 'name' => 'three']
]);