-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
GateCollector::addCheck errors when target is a model with no key #1688
Comments
Hmm so what is |
Can you try to make a PR ? |
In this case I use
Yes, for sure. I might find some time next week, otherwise I'll have time in early November. |
Can you test #1691 ? |
This for reason creates issues with https://github.com/bezhanSalleh/filament-shield who's using spatie's permission and outputs an error like In order for this to be confirmed, toggling the gate collector shows this. |
okay so if ($model->getKeyName() && isset($model[$model->getKeyName()])) {` works? |
Yup. This does seem to fix it :) |
Happy to confirm this is working for my case also. |
I believe that #1653 introduced an undesirable bug when using a Model with no key as the target for a gate check.
It presents itself as
The attribute [id] either does not exist or was not retrieved for model [App\Models\ModelName].
and took me quite a while to realise it was a problem with debug bar, and not with my code, as the vendor trace is hidden by default.I have a model
Attendance
which extends fromIlluminate\Database\Eloquent\Relations\Pivot
. Instances are unique by theforeignKey
andrelatedKey
.AsPivot
handles this internally and makes anisset
check for any primary key before setting keys for query manually.In the case of a Pivot model, you could use the foreign and related keys in the description. But I can imagine a case where a model has been fetched without its
id
which would still break this feature, so it may be wise to include anisset
check of your own and fall back to no description?The text was updated successfully, but these errors were encountered: