You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Passing a closure is extremely helpful. I would not have found out a closure can be passed unless for the video.
Even though I am building complex stuff nowadays I did not know that "$mixed value" in the docblocks can be understood as a callback. Can it?
Kind of a silly question but I'd appreciate an answer.
Thanks.
The text was updated successfully, but these errors were encountered:
mauriciomateus
changed the title
Why does not the documentation say a closure can be passed?
Why does the documentation not say a closure can be passed?
Nov 3, 2017
Hey @mauriciomateus! Yeah there's definitely some tricks in the Laravel source that aren't documented like that. mixed in a docblock doesn't always mean it can accept a callback, but a surprisingly large amount of methods in Laravel can accept a callback instead of a value if it makes sense.
The way I usually find out is just having an insight, "hey I really wish this could accept a callback, I wonder if it can?", then checking the source for that function and seeing if there's any clues.
One of those clues is if Laravel calls the value() function on the argument that gets passed in, which will automatically invoke the value if it's a callback, or just return the value as is otherwise:
One of the more useful things I've learned from this course is to use the source code as documentation. Source diving used to "scare" me, ("this is not my code, I'll spend hours googling this obscure thing instead"). Watching Adam doing it so often and so naturally inspired me to do it myself, even breaking and dd()ing things in the vendor folder without a care in the world, I can always rm -rf it.
I don't want to derail the thread, but I couldn't help myself to take this opportunity to thank @adamwathan for teaching me this. It's a valuable bonus skill, unrelated to TDD (but I probably wouldn't be so adventurous I didn't have the tests backing me up).
Hi:
Passing a closure is extremely helpful. I would not have found out a closure can be passed unless for the video.
Even though I am building complex stuff nowadays I did not know that "$mixed value" in the docblocks can be understood as a callback. Can it?
Kind of a silly question but I'd appreciate an answer.
Thanks.
The text was updated successfully, but these errors were encountered: