© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•5mo ago•
34 replies
borg

Prevented dependency injection of Models (non existent?)

What was the reason for this change: https://github.com/filamentphp/filament/blame/4.x/packages/support/src/Concerns/EvaluatesClosures.php#L85

@ralphjsmit

One can restore this by binding all the models, but this goes against Laravel DI since Models can be injected without issues. A clear commit agains this. I'd like to know the reasons behind this. Thank you.
GitHub
Blaming filament/packages/support/src/Concerns/EvaluatesClosures.ph...
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire - Blaming filament/packages/support/src/Concerns/EvaluatesClosures.php at 4.x · filam...
Blaming filament/packages/support/src/Concerns/EvaluatesClosures.ph...
Solution
In Filament V3 it introduced that you can now alias the injected record to another parameter name instead of
$record
$record
. For example, you could just do
Post $post
Post $post
instead of
Post $record
Post $record
. Whilst this was convenient, there are quite often situations where you think there should be a record, but there actually is not (e.g. in complex forms with relationships etc). In that case, returning
Post $record
Post $record
would fail on that the argument definition does not allow null, prompting a change to
?Post $record
?Post $record
. However, without the above change you linked, the
Post $post
Post $post
would still return a Post model, but then an empty one that does not exist at all created by Laravel dependency injection. This causes then weird bugs in your code later one if you expect
$post
$post
to be the current
$record
$record
and it turns out to be just an empty unsaved model. Therefore, if the requested parameter is an Eloquent parameter that is not of the current record/model, this line has been added to prevent such unwanted empty model resolutions.

See also here: https://github.com/filamentphp/filament/pull/15160
GitHub
Prevent creating non-existent models from container by ralphjsmit ...
Currently, the closure evaluation system works great by resolving any dependencies not provided by name or type from the container. This is very useful. However, there is one situation where it isn...
Prevent creating non-existent models from container by ralphjsmit ...
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Dependency injection.
FilamentFFilament / ❓┊help
3y ago
Dependency Injection in Filament
FilamentFFilament / ❓┊help
2y ago
Dependency Injection on Custom Fields
FilamentFFilament / ❓┊help
2y ago
Dependency injection for CreateRecord page
FilamentFFilament / ❓┊help
2y ago