Skip to content
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

[5.5] If applied this commit adds the blade directive for the Switch statement #19758

Merged
merged 4 commits into from
Jun 25, 2017
Merged

[5.5] If applied this commit adds the blade directive for the Switch statement #19758

merged 4 commits into from
Jun 25, 2017

Conversation

introwit
Copy link
Contributor

@introwit introwit commented Jun 25, 2017

  • Contributors, since this has not been added till now I think there might be a valid reason for that which I am not aware of, so feel free to close this PR :)
  • Reason for doing it: To practice making a core contribution(as this is my first time) and giving back to the amazing Laravel community what I can.

How to use:

@switch($i)

    @case(1)
    <p>Case 1</p>
    @break

    @case(2)
    <p>Case 2</p>
    @break

    @default
    <p>Default</p>

@endswitch

@taylorotwell taylorotwell merged commit 33883fe into laravel:master Jun 25, 2017
@Faks
Copy link

Faks commented Jun 25, 2017

good news i like it will come handy.

@josephzidell
Copy link
Contributor

Does this support double cases?

@switch
    @case(1)
    @case(2)
           <someDiv />
    @case(3)
           <anotherDiv />
    @break
@endswitch

@introwit
Copy link
Contributor Author

@josephzidell yes it does.

@nunomaduro
Copy link
Member

That is really helpful. Thanks!

@introwit
Copy link
Contributor Author

@nunomaduro cheers :) Thank you too for laravel zero Nuno ❤️

@ilmoralito
Copy link

Remarkable thanks community

protected function compileCase($value)
{
if ($this->firstCaseInSwitch) {
$this->firstCaseInSwitch = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This'll break with multiple switch statements in a file, right? It'll print <?php switch($x): <?php case....

Can the firstCaseInSwitch be removed and have compileSwitch just close the ?>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danharper Implemented the firstCaseInSwitch because of the following as worded in the PHP docs:

Warning
Any output (including whitespace) between a switch statement and the first case will result in a syntax error

Trying to fix the issue you just found out about multiple switch statements in a file, any help or suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also noticed this and submitted a PR already: #19760. I should have mentioned that here.

@OwenMelbz
Copy link
Contributor

Nice PR, but has made me think at what point do we just start writing vanilla php in these templates? Wondering that it seems a like we're creating our own language subset that's less flexible?

@bitfumes
Copy link

bitfumes commented Jun 26, 2017

This is nice addition to Laravel 5.5, here is how it works on Laravel 5.5 https://goo.gl/3L4D52

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

Successfully merging this pull request may close these issues.

10 participants