-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[9.x] Add handling of object being passed into old method #41842
Conversation
I personally think we shouldn't do this and this is best handled in userland but let's see what @taylorotwell says. |
There was no coupling before. You can make instanceof checks against classes that don't exist. So |
Ah damn, I always forget about that behavior of |
I didn't realise that was a behavior of |
@Drewdan I generally kinda like this PR overall - can you revert your recent changes and bring back the instanceof Model check so I can review it again in that form? |
@taylorotwell - I shall do, I will post a new commit shortly |
@taylorotwell - I have pushed a new commit up. This one is different from my initial commit in that is just checks to see if The reason for this is I believe I have also left the array test in just to make sure this does not break any existing behavior |
Thanks! |
Thank you :) |
I know this is an old PR by now, but I've finally had a change to upgrade my Laravel version on one of my apps, and found this caused a breaking change for me. I've fixed up my code, so it's not an issue anymore for me, but I thought I'd make a note 🙂 In my scenario, I'm using the @if(old('operators.' . $loopIndex . '.isAllocated', $jobAllocation)) checked @endif Previously, it would return the default variable if no old value was set, as such would be But now it's trying to look for the key I've updated my code now to just wrap the variable in an @if(old('operators.' . $loopIndex . '.isAllocated', isset($jobAllocation))) checked @endif Hope this helps someone else if they are running into a similar problem! |
@joshhanley that's interesting, I'd never thought of that sort of usage. Thank you for documenting it here, though. I hope I didn't cause too much of a headache for you! |
Hey Guys!
This PR allows users to pass in a Model as the default parameter to the old helper function.
If you had a form to update a username. You might set the value to something like this:
This will find the old value in the request or, default to the
$user->name
value which is being pulled from the User model if there is no old value.This PR changes this to allow the following
The method has been updated to check if the default value being passed is an instance of a Model and gets the attribute based on the key
As many developers will follow cruddy conventions, and have their attributes named the same as their input names, so they can mass insert, I believe this would streamline form creation (if only slightly)
I have added a test to cover this behaviour, and I have also added a test to cover setting the default as an array, to ensure no existing behaviour is broken by this change.
An alternate approach I considered would be to add a new helper method, (though, not sure what the name would be,
oldAttribute($class, $key)
maybe?) , which would do this behaviour independently of the old helper method. I'd be happy to scope this out if this approach would be preferred.Thanks for looking :)