-
Notifications
You must be signed in to change notification settings - Fork 55
Open
Description
Within my app service provider I'm calling:
Model::shouldBeStrict(! $this->app->isProduction());
I'm then calling a query as follows:
$place = Place::query()
->withDistance('location', new Point(1, 1, 4326))
->first();
In a HTTP resource I'm then accessing $this->distance
.
I then get an exception (MissingAttributeException
).
When I comment out shouldBeStrict
, everything works fine. Is there any way around this?
Activity
MatanYadaev commentedon Mar 22, 2025
Can you send a PR with a failing test that reproduces this issue? I tried reproducing this issue without success.
ultrono commentedon Mar 22, 2025
Sorry no PR, my example describes my exact use case. I'm assuming this is because the
withDistance
method returning an attribute not on my model, which is what Laravel's built in strict mode prevents.Changing my coilumn name to "distance" or adding a third argument to
withDistance
may be worth a try i.e.With this I can do
$this->location
in model, which in theory will pass Laravel's strict mode. Will report back.MatanYadaev commentedon Mar 22, 2025
As far as I know, the error is thrown only when the data is not in the
$model->attributes
array. In this case, it should be, because it was returned from the database. Maybe you load thedistance
attribute conditionally?