Skip to content

Commit 02ffa40

Browse files
authored
Add Laravel's withoutForeignKeyConstraints method to Schema Builder (#7684)
1 parent c9d3cb6 commit 02ffa40

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/Schema/Builder.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,20 @@ public function disableForeignKeyConstraints(): bool
353353
);
354354
}
355355

356+
/**
357+
* Disable foreign key constraints during the execution of a callback.
358+
*/
359+
public function withoutForeignKeyConstraints(Closure $callback): mixed
360+
{
361+
$this->disableForeignKeyConstraints();
362+
363+
try {
364+
return $callback();
365+
} finally {
366+
$this->enableForeignKeyConstraints();
367+
}
368+
}
369+
356370
/**
357371
* Get the foreign keys for a given table.
358372
*/

src/Schema/Schema.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* @method static void rename(string $from, string $to)
4545
* @method static bool enableForeignKeyConstraints()
4646
* @method static bool disableForeignKeyConstraints()
47+
* @method static mixed withoutForeignKeyConstraints(\Closure $callback)
4748
* @method static \Hyperf\Database\Connection getConnection()
4849
* @method static Builder setConnection(\Hyperf\Database\Connection $connection)
4950
* @method static void blueprintResolver(\Closure $resolver)

0 commit comments

Comments
 (0)