diff --git a/docs/04-pages.md b/docs/04-pages.md index ea04023c..3911e0d4 100644 --- a/docs/04-pages.md +++ b/docs/04-pages.md @@ -77,10 +77,10 @@ You can also pass an array of arguments to the default action using the `$defaul public $defaultActionArguments = ['step' => 2]; ``` -Alternatively, you can open an action modal when a page loads by specifying the `defaultAction` as a query string parameter to the page: +Alternatively, you can open an action modal when a page loads by specifying the `action` as a query string parameter to the page: ``` -/admin/products/edit/932510?defaultAction=onboarding +/admin/products/edit/932510?action=onboarding ``` ### Refreshing form data diff --git a/src/Facades/Filament.php b/src/Facades/Filament.php index 06163a12..0202e5e5 100644 --- a/src/Facades/Filament.php +++ b/src/Facades/Filament.php @@ -71,6 +71,7 @@ * @method static string | null getRequestPasswordResetUrl(array $parameters = []) * @method static string getResetPasswordUrl(string $token, CanResetPassword | Model | Authenticatable $user, array $parameters = []) * @method static array getResources() + * @method static array getResourceUrl(string | Model $model, string $name = 'index', array $parameters = [], bool $isAbsolute = false, ?Model $tenant = null) * @method static string getSidebarWidth() * @method static Model | null getTenant() * @method static string | null getTenantAvatarUrl(Model $tenant) diff --git a/src/FilamentManager.php b/src/FilamentManager.php index 978dad2b..043a32c5 100644 --- a/src/FilamentManager.php +++ b/src/FilamentManager.php @@ -31,6 +31,7 @@ use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Event; +use Throwable; class FilamentManager { @@ -342,6 +343,14 @@ public function getResources(): array return $this->getCurrentPanel()->getResources(); } + /** + * @param array $parameters + */ + public function getResourceUrl(string | Model $model, string $name = 'index', array $parameters = [], bool $isAbsolute = true, ?Model $tenant = null): string + { + return $this->getCurrentPanel()->getResourceUrl($model, $name, $parameters, $isAbsolute, $tenant); + } + public function getSidebarWidth(): string { return $this->getCurrentPanel()->getSidebarWidth(); diff --git a/src/FilamentServiceProvider.php b/src/FilamentServiceProvider.php index bdbcfa2e..ef17c62e 100644 --- a/src/FilamentServiceProvider.php +++ b/src/FilamentServiceProvider.php @@ -45,15 +45,15 @@ public function configurePackage(Package $package): void public function packageRegistered(): void { $this->app->scoped('filament', function (): FilamentManager { - return new FilamentManager(); + return new FilamentManager; }); $this->app->singleton(PanelRegistry::class, function (): PanelRegistry { - return new PanelRegistry(); + return new PanelRegistry; }); $this->app->scoped(NavigationManager::class, function (): NavigationManager { - return new NavigationManager(); + return new NavigationManager; }); $this->app->bind(EmailVerificationResponseContract::class, EmailVerificationResponse::class); diff --git a/src/Pages/BasePage.php b/src/Pages/BasePage.php index 498cab5e..ac73cea1 100644 --- a/src/Pages/BasePage.php +++ b/src/Pages/BasePage.php @@ -126,7 +126,7 @@ protected function onValidationError(ValidationException $exception): void protected function halt(): void { - throw new Halt(); + throw new Halt; } protected function callHook(string $hook): void diff --git a/src/Panel.php b/src/Panel.php index 4ddf115d..c5f52ef5 100644 --- a/src/Panel.php +++ b/src/Panel.php @@ -12,6 +12,7 @@ class Panel extends Component { + use Panel\Concerns\CanGenerateResourceUrls; use Panel\Concerns\HasAssets; use Panel\Concerns\HasAuth; use Panel\Concerns\HasAvatars; diff --git a/src/Panel/Concerns/CanGenerateResourceUrls.php b/src/Panel/Concerns/CanGenerateResourceUrls.php new file mode 100644 index 00000000..09dc95b6 --- /dev/null +++ b/src/Panel/Concerns/CanGenerateResourceUrls.php @@ -0,0 +1,29 @@ + $parameters + */ + public function getResourceUrl(string | Model $model, string $name = 'index', array $parameters = [], bool $isAbsolute = true, ?Model $tenant = null): string + { + $modelClass = is_string($model) ? $model : $model::class; + + $resource = $this->getModelResource($modelClass) ?? throw new Exception("No Filament resource found for model [{$modelClass}]."); + + if ( + ($model instanceof Model) && + in_array($name, ['edit', 'view']) + ) { + $parameters['record'] ??= $model; + } + + return $resource::getUrl($name, $parameters, $isAbsolute, $this->getId(), $tenant); + } +} diff --git a/src/Panel/Concerns/HasRoutes.php b/src/Panel/Concerns/HasRoutes.php index 1527d95c..f926ca48 100644 --- a/src/Panel/Concerns/HasRoutes.php +++ b/src/Panel/Concerns/HasRoutes.php @@ -188,7 +188,7 @@ public function getUrl(?Model $tenant = null): ?string Filament::setTenant($tenant, isQuiet: true); } - $this->navigationManager = new NavigationManager(); + $this->navigationManager = new NavigationManager; $navigation = $this->navigationManager->get(); diff --git a/src/Panel/Concerns/HasTenancy.php b/src/Panel/Concerns/HasTenancy.php index bf2721ea..959aba9e 100644 --- a/src/Panel/Concerns/HasTenancy.php +++ b/src/Panel/Concerns/HasTenancy.php @@ -189,7 +189,7 @@ public function getTenant(string $key): Model ->resolveRouteBinding($key, $this->getTenantSlugAttribute()); if ($record === null) { - throw (new ModelNotFoundException())->setModel($tenantModel, [$key]); + throw (new ModelNotFoundException)->setModel($tenantModel, [$key]); } return $record; diff --git a/src/Resources/Pages/Concerns/InteractsWithRecord.php b/src/Resources/Pages/Concerns/InteractsWithRecord.php index c1208a34..c376c721 100644 --- a/src/Resources/Pages/Concerns/InteractsWithRecord.php +++ b/src/Resources/Pages/Concerns/InteractsWithRecord.php @@ -23,7 +23,7 @@ protected function resolveRecord(int | string $key): Model $record = static::getResource()::resolveRecordRouteBinding($key); if ($record === null) { - throw (new ModelNotFoundException())->setModel($this->getModel(), [$key]); + throw (new ModelNotFoundException)->setModel($this->getModel(), [$key]); } return $record; diff --git a/src/helpers.php b/src/helpers.php index 03266970..1c312932 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -34,7 +34,7 @@ function authorize(string $action, Model | string $model, bool $shouldCheckPolic ); if ($response === false) { - throw new AuthorizationException(); + throw new AuthorizationException; } if (! $response instanceof Response) {