Add the Conditionable
trait to the FormBuilder
#152
Closed
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.
Hey! This PR proposes adding the
Illuminate\Support\Traits\Conditionable
trait to theLaravel\Prompts\FormBuilder
class.I love using
when
in my Laravel apps so I can chain my method calls together. So I reached out today to use it when building a form in Prompts and noticed it didn't exist.Here's an example use case of a form using a standard
if
statement to add a new user to the app:Using
when
it could be rewritten like so:I did notice that Prompts isn't specific to Laravel and can be used in other PHP apps, so I don't know if keeping the dependencies lightweight will play a part in the decision to merge this. But from looking at the Composer files, I think Prompts includes
illuminate/collections
which in turn requiresilluminate/conditionable
. So if I'm right, it means we already have access to this trait without needing to add any new dependencies.If this is something you think might be helpful to other devs, please give me a shout if you might want anything changed on this PR. If not, that's totally cool, at least I gave it a shot! 😄