Skip to content

Commit 4ca509e

Browse files
authored
Merge pull request #2886 from alisalehi1380/patch-1
Refactor exception handling in migration stub
2 parents 9129e16 + d81d9ce commit 4ca509e

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

database/migrations/create_permission_tables.php.stub

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +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-
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.'));
20+
throw_if(empty($tableNames), Exception::class, 'Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
21+
throw_if($teams && empty($columnNames['team_foreign_key'] ?? null), Exception::class, 'Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.');
2222

2323
Schema::create($tableNames['permissions'], static function (Blueprint $table) {
2424
// $table->engine('InnoDB');
@@ -123,9 +123,7 @@ return new class extends Migration
123123
{
124124
$tableNames = config('permission.table_names');
125125

126-
if (empty($tableNames)) {
127-
throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
128-
}
126+
throw_if(empty($tableNames), Exception::class, 'Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
129127

130128
Schema::drop($tableNames['role_has_permissions']);
131129
Schema::drop($tableNames['model_has_roles']);

0 commit comments

Comments
 (0)