Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActionRequest::actionableKey() supports only int Primary Keys #6605

Closed
alies-dev opened this issue Dec 15, 2024 · 1 comment
Closed

ActionRequest::actionableKey() supports only int Primary Keys #6605

alies-dev opened this issue Dec 15, 2024 · 1 comment
Labels
bug Verified bug by the Nova team fix incoming A fix is in review
Milestone

Comments

@alies-dev
Copy link

alies-dev commented Dec 15, 2024

  • Laravel Version: 11.35.0
  • Nova Version: 5.0
  • PHP Version: 8.3.17

Description:

For models, I used UUID and got this error when running Nova Actions (only on Nova v5):

[2024-12-15 12:36:39] local.ERROR: Laravel\Nova\Http\Requests\ActionRequest::actionableKey(): Return value must be of type int, string returned {"userId":1,"exception":"[object] (TypeError(code: 0): Laravel\\Nova\\Http\\Requests\\ActionRequest::actionableKey(): Return value must be of type int, string returned at /var/www/html/vendor/laravel/nova/src/Http/Requests/ActionRequest.php:223)
[stacktrace]
#0 /var/www/html/vendor/laravel/nova/src/Actions/ActionEvent.php(295): Laravel\\Nova\\Http\\Requests\\ActionRequest->actionableKey()
#1 [internal function]: Laravel\\Nova\\Actions\\ActionEvent::Laravel\\Nova\\Actions\\{closure}()
#2 /var/www/html/vendor/laravel/framework/src/Illuminate/Collections/Arr.php(609): array_map()
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Collections/Collection.php(795): Illuminate\\Support\\Arr::map()
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Collection.php(375): Illuminate\\Support\\Collection->map()
#5 /var/www/html/vendor/laravel/nova/src/Actions/ActionEvent.php(291): Illuminate\\Database\\Eloquent\\Collection->map()
#6 /var/www/html/vendor/laravel/nova/src/Actions/DispatchAction.php(192): Laravel\\Nova\\Actions\\ActionEvent::createForModels()
#7 [internal function]: Laravel\\Nova\\Actions\\DispatchAction->Laravel\\Nova\\Actions\\{closure}()
#8 /var/www/html/vendor/laravel/nova/src/Concerns/InteractsWithActionEvent.php(37): call_user_func()
#9 /var/www/html/vendor/laravel/nova/src/Actions/DispatchAction.php(190): Laravel\\Nova\\Nova::usingActionEvent()
#10 /var/www/html/vendor/laravel/nova/src/Actions/Transaction.php(26): Laravel\\Nova\\Actions\\DispatchAction->Laravel\\Nova\\Actions\\{closure}()
#11 /var/www/html/vendor/laravel/nova/src/Actions/DispatchAction.php(189): Laravel\\Nova\\Actions\\Transaction::run()
#12 /var/www/html/vendor/laravel/nova/src/Actions/DispatchAction.php(179): Laravel\\Nova\\Actions\\DispatchAction->dispatchSynchronouslyForCollection()
#13 /var/www/html/vendor/laravel/nova/src/Actions/DispatchAction.php(137): Laravel\\Nova\\Actions\\DispatchAction->forModels()
#14 /var/www/html/vendor/laravel/nova/src/Http/Requests/ActionRequest.php(94): Laravel\\Nova\\Actions\\DispatchAction->Laravel\\Nova\\Actions\\{closure}()
#15 /var/www/html/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(259): Laravel\\Nova\\Http\\Requests\\ActionRequest->Laravel\\Nova\\Http\\Requests\\{closure}()
#16 /var/www/html/vendor/laravel/nova/src/Http/Requests/ActionRequest.php(93): Illuminate\\Support\\LazyCollection->each()
#17 /var/www/html/vendor/laravel/nova/src/Actions/DispatchAction.php(129): Laravel\\Nova\\Http\\Requests\\ActionRequest->chunks()
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/helpers.php(520): Laravel\\Nova\\Actions\\DispatchAction->Laravel\\Nova\\Actions\\{closure}()
#19 /var/www/html/vendor/laravel/nova/src/Actions/DispatchAction.php(84): with()

Solution

-public function actionableKey($model): int
+public function actionableKey($model): int | string
{
    return $this->isPivotAction()
        ? $model->{$this->pivotRelation()->getForeignPivotKeyName()}
        : $model->getKey();
}
@crynobone crynobone added bug Verified bug by the Nova team fix incoming A fix is in review labels Dec 15, 2024
@crynobone crynobone added this to the 5.0.x milestone Dec 17, 2024
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Verified bug by the Nova team fix incoming A fix is in review
Projects
None yet
Development

No branches or pull requests

2 participants