Skip to content

Commit 1387368

Browse files
authored
Refactor exception throwing in migration file to use throw_if (spatie#2819)
Refactor: refactoring exception throwing
1 parent 9bdd933 commit 1387368

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

database/migrations/create_permission_tables.php.stub

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ return new class extends Migration
1717
$pivotRole = $columnNames['role_pivot_key'] ?? 'role_id';
1818
$pivotPermission = $columnNames['permission_pivot_key'] ?? 'permission_id';
1919

20-
if (empty($tableNames)) {
21-
throw new \Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
22-
}
23-
if ($teams && empty($columnNames['team_foreign_key'] ?? null)) {
24-
throw new \Exception('Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.');
25-
}
20+
throw_if(empty($tableNames), new Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.'));
21+
throw_if($teams && empty($columnNames['team_foreign_key'] ?? null), new Exception('Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.'));
2622

2723
Schema::create($tableNames['permissions'], static function (Blueprint $table) {
2824
// $table->engine('InnoDB');

0 commit comments

Comments
 (0)