-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multiple filament panel (also tenant), and add new column for…
… deteching filament panel path
- Loading branch information
1 parent
287a6b1
commit 2d73fb2
Showing
10 changed files
with
220 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
use SolutionForest\FilamentAccessManagement\Support\Utils; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table(Utils::getMenuTableName(), function (Blueprint $table) { | ||
$table->boolean('is_filament_panel')->after('uri')->default(false); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
if (empty(Utils::getMenuTableName())) { | ||
throw new \Exception('Error: config/filament-access-management.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.'); | ||
} | ||
|
||
Schema::table(Utils::getMenuTableName(), function (Blueprint $table) { | ||
$table->dropColumn('is_filament_panel'); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace SolutionForest\FilamentAccessManagement\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Str; | ||
use SolutionForest\FilamentAccessManagement\Support\Utils; | ||
|
||
use function Laravel\Prompts\progress; | ||
|
||
class Upgrade extends Command | ||
{ | ||
|
||
protected $signature = 'filament-access-management:upgrade'; | ||
|
||
public $description = 'Upgrade FilamentAccessManagement'; | ||
|
||
public function handle(): int | ||
{ | ||
$this->upgradeMenuUrl(); | ||
|
||
return static::SUCCESS; | ||
} | ||
|
||
private function upgradeMenuUrl() | ||
{ | ||
$model = Utils::getMenuModel(); | ||
|
||
// Find the old uri on FilamentAccessManagement v1 | ||
$v1PathRecords = $model::where(function ($query) { | ||
return $query | ||
// ->orWhere('uri', '/') // Admin default page on filament v2 | ||
->orWhere('uri', '/admin') // Admin dashboard page on filament v2 | ||
->orWhere('uri', 'like', '/admin/%'); // The page(s) under admin on filament v2 | ||
}) | ||
->where('is_filament_panel', false) // default value | ||
->get(); | ||
|
||
progress('Updating uri of menu as current version', count($v1PathRecords), function () use ($v1PathRecords) { | ||
|
||
foreach ($v1PathRecords as $v1PathRecord) { | ||
|
||
try { | ||
|
||
$newUri = (string)str($v1PathRecord->uri) | ||
->replace('/admin', ''); | ||
|
||
$v1PathRecord->update([ | ||
'uri' => $newUri, | ||
'is_filament_panel' => true, | ||
]); | ||
|
||
} catch (\Exception $e) { | ||
$this->error("Updating uri of menu failed (Detail: {$e->getMessage()})"); | ||
} | ||
} | ||
}); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.