Skip to content
This repository has been archived by the owner on Feb 26, 2018. It is now read-only.

Conditional element method calls #110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conditional element method calls #110

wants to merge 2 commits into from

Conversation

jesseleite
Copy link
Contributor

@jesseleite jesseleite commented Dec 7, 2016

Similar to the existing magic attribute setters:

Form::text('meme')->lol('catz')
// <input type="text" name="meme" lol="catz">

This PR proposes conditional magic attribute setters:

Form::text('name')->disabledIf(true)
// <input type="text" name="meme" disabled="disabled">

Form::text('name')->disabledIf(false)
// <input type="text" name="meme">

Form::text('name')->maxlengthIf(true, '5')
// <input type="text" name="meme" maxlength="5">

Form::text('name')->maxlengthIf(false, '5')
// <input type="text" name="meme">

This works using the magic __call() method, detecting if last two characters in method call are If. The first param being $condition (can be any expression), and the following params are just passed onto the desired method using call_user_func_array().

@jesseleite jesseleite mentioned this pull request Dec 7, 2016
@coveralls
Copy link

coveralls commented Dec 7, 2016

Coverage Status

Coverage increased (+0.09%) to 94.848% when pulling 4b97295 on JesseLeite:conditional-element-method-calls into da9e21c on adamwathan:master.

@axyr
Copy link

axyr commented Dec 7, 2016

This is very nice!

@axyr
Copy link

axyr commented Dec 7, 2016

What about this :

{!! BootForm::open()->action(route('companies'))->multipart()->putIf($company->getKey()) !!}

So we don't have to do this:

@if($company->getKey())
    {!! BootForm::open()->action(route('companies'))->multipart()->put() !!}
@else
    {!! BootForm::open()->action(route('companies'))->multipart() !!}
@endif

Edit : And ofcourse i mean Form::open() ..... :)

@jesseleite
Copy link
Contributor Author

@axyr Because my code is on Element, and because FormOpen extends Element, this is already possible:

@axyr
Copy link

axyr commented Dec 7, 2016

Great!

@axyr
Copy link

axyr commented Dec 15, 2016

@adamwathan can you merge some of the very very nice pull requests???

@jesseleite
Copy link
Contributor Author

I know this was implemented in #99, but my case for magic method implementation here: #99 (comment)

...That said, if you want to close this PR, I won't be sad :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants