I have an array like this one :
0 => array:2 [
\"name\" => \"Data1\"
\"type\" => \"value1\"
],
1 => array:2 [
\"name\" => \"Da
I use this method to insert non-duplicate data.
But this method consumes performance.
class TestController extends Controller
{
public function test()
{
DB::transaction(function () {
$insertedIds = [];
//the name key is unique, so i use the firstOrCreate method
for ($i = 0; $i < 10; $i++) {
$tag = Tags::firstOrCreate(['name' => 30 + $i]);
$id = $tag->id;
array_push($insertedIds, $id);
}
dump($insertedIds);
});
}
}