Conditions | 1 |
Paths | 1 |
Total Lines | 13 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
24 | protected static function makeManyToManySeed(string $sourceModel, string $targetModel, string $relationship): string |
||
25 | { |
||
26 | return <<<EOF |
||
27 | |||
28 | try { |
||
29 | \${$targetModel}Items = App\\Models\\$targetModel::all(); |
||
30 | \$model->{$relationship}()->attach( |
||
31 | \${$targetModel}Items->random(rand(1, 3))->pluck('id')->toArray() |
||
32 | ); |
||
33 | } |
||
34 | catch (\InvalidArgumentException \$e) { |
||
35 | \$model->{$relationship}()->attach( |
||
36 | \${$targetModel}Items->random(1)->pluck('id')->toArray() |
||
37 | ); |
||
42 |