[5.x] Prevent error when cascadeContent
is an Eloquent Model
#10759
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request fixes an issue when passing an Eloquent Model into a view's `->cascadeContents() method.
I'm currently fixing a bug in Runway, with its frontend routing feature, where the
page
variable isn't available in Blade views (see statamic-rad-pack/runway#590).The
page
variable is only set when the view hascascadeContent
set, whereas previously we were only passing an array of the augmented model into theView::with()
method.However, when passing the model to
View::cascadeContents()
, it resulted in an error because the model doesn't have anid
method on it.I could add an ID method but that has caused issues in the past where folks have already implemented their own
id
methods.Ideally, for Eloquent Models, it'd use the model's key anyway.
Anyways, feel free to reject if you don't want this in Core and I'll try and find another way around it.