filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
19.29k stars 2.96k forks source link

Can't evaluate Laravel Contextual Attributes in closures #14572

Closed mokhosh closed 4 weeks ago

mokhosh commented 1 month ago

Package

filament/filament

Package Version

v3.2.119

Laravel Version

v11.4.0

Livewire Version

v3.5.0

PHP Version

8.3.12

Problem description

You can't pass in Laravel Contextual Attributes into closures:

->action(function (User $user, #[CurrentUser] User $admin) {

Both of the above models will be the Table record, and if you don't type-hint admin it will not resolve and will throw an exception. So, you have to do something like this:

->action(function (User $user) {
    /** @var User $admin */
    $admin = Auth::user();

Expected behavior

You should be able to pass Contextual Attributes into closures.

Steps to reproduce

  1. Pass a Contextual Attribute into any closure that is being evaluated with the evaluate method.

Reproduction repository (issue will be closed if this is not valid)

https://github.com/mokhosh/filament-contextual-attr-bug

Relevant log output

No response

Donate 💰 to fund this issue

Fund with Polar

danharrin commented 4 weeks ago

Hi, this is a feature request, and not something I'm going to prioritise at the moment. We do not use Laravel's container to evaluate closures as we added many new features to our implementation. I would accept a PR for v4.

mokhosh commented 4 weeks ago

@danharrin would you add this to v3 if we use the Laravel container as the last fallback?

danharrin commented 4 weeks ago

It is about the amount of time it takes for me to review new features for v3, not about breaking changes in this case

mokhosh commented 4 weeks ago

ok fair enough.