0

the following statement

@switch($i)
@case(1)
First case...
@break
@case(2)
Second case...
@break
@default
Default case...
@endswitch

works properly in one project, but in another project the following message appears:

FatalErrorException
'break' not in the 'loop' or 'switch' context

Laravel version is 5.6.28
Ubuntu 18.04

I'm afraid that, as the computer is rarely updated, when I updated something crashed in Laravel

6
  • Check your /storage/framework/views folder for the compiled view to check what kind of markup it generated. It should give you hints as to what went wrong.
    – apokryfos
    Sep 5, 2018 at 7:46
  • the interpreter is ignoring @switch. The code is: @switch($tipo) @case(1) First case... <?php break; ?>. As you see, it is missing <$php switch ?>
    – cassio
    Sep 5, 2018 at 9:59
  • Double check that the correct laravel version is installed in both projects. Switch was added in Laravel 5.5 so if one project is at say 5.4 then it will produce this exact behaviour
    – apokryfos
    Sep 5, 2018 at 11:55
  • probably you are right. the current version is 5.6 but, as I created the project some time ago, the version could be 5.4 or lower. In this case, how could I fix the problem?
    – cassio
    Sep 5, 2018 at 12:41
  • If you have 5,4 then follow the steps in the upgrade guide , if it's even lower then you may need to upgrade in steps e.g. if you have 5.3 then upgrade to 5.4 and then 5.5. Mostly you don't actually need to do much besides updating your dependencies ,but there's a few things that may not be backwards compatible
    – apokryfos
    Sep 5, 2018 at 13:03

2 Answers 2

0

Maybe you can try @breakswitch

@switch($i) @case(1) First case... @breakswitch @case(2) Second case... @breakswitch @default Default case...

@endswitch

0

I checked my /storage/framework/views folder.
@breakswitch gives no error, but the problem is still the same: the interpreter does not recognize the command @switch, so my web page shows the following:
@case(1) First case... @breakswitch @case(2) Second case... @breakswitch @default Default case... @endswitch

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.