@@ -2474,12 +2474,12 @@ public function testTouchingBiDirectionalChaperonedModelUpdatesAllRelatedTimesta
2474
2474
}
2475
2475
}
2476
2476
2477
- public function testCanInsertWithCasts ()
2477
+ public function testCanEnrichAndInsert ()
2478
2478
{
2479
2479
DB ::enableQueryLog ();
2480
2480
Carbon::setTestNow ('2025-03-15T07:32:00Z ' );
2481
2481
2482
- $ this ->assertTrue (EloquentTestUser::mergeAttributesBeforeInsert ()-> insert ([
2482
+ $ this ->assertTrue (EloquentTestUser::hydrateAndInsert ([
2483
2483
['email ' => 'taylor@laravel.com ' , 'birthday ' => null ],
2484
2484
['email ' => 'nuno@laravel.com ' , 'birthday ' => new Carbon ('1980-01-01 ' )],
2485
2485
['email ' => 'tim@laravel.com ' , 'birthday ' => '1987-11-01 ' , 'created_at ' => '2025-01-02T02:00:55 ' , 'updated_at ' => Carbon::parse ('2025-02-19T11:41:13 ' )],
@@ -2505,7 +2505,7 @@ public function testCanInsertWithCasts()
2505
2505
2506
2506
DB ::flushQueryLog ();
2507
2507
2508
- $ this ->assertTrue (EloquentTestWithJSON::mergeAttributesBeforeInsert ()-> insert ([
2508
+ $ this ->assertTrue (EloquentTestWithJSON::hydrateAndInsert ([
2509
2509
['id ' => 1 , 'json ' => ['album ' => 'Keep It Like a Secret ' , 'release_date ' => '1999-02-02 ' ]],
2510
2510
['id ' => 2 , 'json ' => (object ) ['album ' => 'You In Reverse ' , 'release_date ' => '2006-04-11 ' ]],
2511
2511
]));
@@ -2520,15 +2520,15 @@ public function testCanInsertWithCasts()
2520
2520
});
2521
2521
}
2522
2522
2523
- public function testCanInsertWithCastsWithUniqueStringIds ()
2523
+ public function testCanHydrateAndInsertWithUniqueStringIds ()
2524
2524
{
2525
2525
Str::createUuidsUsingSequence ([
2526
2526
'00000000-0000-7000-0000-000000000000 ' ,
2527
2527
'11111111-0000-7000-0000-000000000000 ' ,
2528
2528
'22222222-0000-7000-0000-000000000000 ' ,
2529
2529
]);
2530
2530
2531
- $ this ->assertTrue (ModelWithUniqueStringIds::mergeAttributesBeforeInsert ()-> insert ([
2531
+ $ this ->assertTrue (ModelWithUniqueStringIds::hydrateAndInsert ([
2532
2532
[
2533
2533
'name ' => 'Taylor ' , 'role ' => IntBackedRole::Admin, 'role_string ' => StringBackedRole::Admin,
2534
2534
],
@@ -2567,6 +2567,37 @@ public function testCanInsertWithCastsWithUniqueStringIds()
2567
2567
$ this ->assertSame ('22222222-0000-7000-0000-000000000000 ' , $ chris ->uuid );
2568
2568
}
2569
2569
2570
+ public function testHydrateAndInsertOrIgnore ()
2571
+ {
2572
+ Str::createUuidsUsingSequence ([
2573
+ '00000000-0000-7000-0000-000000000000 ' ,
2574
+ '11111111-0000-7000-0000-000000000000 ' ,
2575
+ '22222222-0000-7000-0000-000000000000 ' ,
2576
+ ]);
2577
+
2578
+ $ this ->assertEquals (1 , ModelWithUniqueStringIds::hydrateAndInsertOrIgnore ([
2579
+ [
2580
+ 'id ' => 1 , 'name ' => 'Taylor ' , 'role ' => IntBackedRole::Admin, 'role_string ' => StringBackedRole::Admin,
2581
+ ],
2582
+ ]));
2583
+
2584
+ $ this ->assertSame (1 , ModelWithUniqueStringIds::hydrateAndInsertOrIgnore ([
2585
+ [
2586
+ 'id ' => 1 , 'name ' => 'Taylor ' , 'role ' => IntBackedRole::Admin, 'role_string ' => StringBackedRole::Admin,
2587
+ ],
2588
+ [
2589
+ 'id ' => 2 , 'name ' => 'Nuno ' ,
2590
+ ],
2591
+ ]));
2592
+
2593
+ $ models = ModelWithUniqueStringIds::get ();
2594
+ $ this ->assertSame ('00000000-0000-7000-0000-000000000000 ' , $ models ->firstWhere ('name ' , 'Taylor ' )->uuid );
2595
+ $ this ->assertSame (
2596
+ ['uuid ' => '22222222-0000-7000-0000-000000000000 ' , 'role ' => IntBackedRole::User],
2597
+ $ models ->firstWhere ('name ' , 'Nuno ' )->only ('uuid ' , 'role ' )
2598
+ );
2599
+ }
2600
+
2570
2601
public function testMergeBeforeInsertGetId ()
2571
2602
{
2572
2603
Str::createUuidsUsingSequence ([
@@ -2575,7 +2606,7 @@ public function testMergeBeforeInsertGetId()
2575
2606
2576
2607
DB ::enableQueryLog ();
2577
2608
2578
- $ this ->assertIsInt ($ newId = ModelWithUniqueStringIds::mergeAttributesBeforeInsert ()-> insertGetId ([
2609
+ $ this ->assertIsInt ($ newId = ModelWithUniqueStringIds::hydrateAndinsertGetId ([
2579
2610
'name ' => 'Taylor ' ,
2580
2611
'role ' => IntBackedRole::Admin,
2581
2612
'role_string ' => StringBackedRole::Admin,
0 commit comments