Skip to content

Commit

Permalink
[9.x] Add withoutForeignKeyConstraints() to disable foreign key const…
Browse files Browse the repository at this point in the history
…raints in a callback (#45601)

* Add withoutForeignKeyConstraints() to disable foreign key constraints in a callback

* fix param

* Update Builder.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
phh and taylorotwell authored Jan 11, 2023
1 parent f2d7f14 commit 00d2058
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,23 @@ public function disableForeignKeyConstraints()
);
}

/**
* Disable foreign key constraints during the execution of a callback.
*
* @param \Closure $callback
* @return mixed
*/
public function withoutForeignKeyConstraints(Closure $callback)
{
$this->disableForeignKeyConstraints();

$result = $callback();

$this->enableForeignKeyConstraints();

return $result;
}

/**
* Execute the blueprint to build / modify the table.
*
Expand Down

0 comments on commit 00d2058

Please sign in to comment.