loading...

switch case in laravel

pakainfocom profile image pakainfo ・1 min read

switch case in laravel

In this session switch case in laravel, we will discuss how to use switch case in Laravel. In Laravel 5.5 and above versions @Switch is built into the Blade. So it can be used just like in plain PHP.


@switch($login_error)
    @case(1)

         `E-mail` input is empty! 

        @break

    @case(2)

        `Password` input is empty! 

        @break

    @default


        Something went wrong, please try again 

@endswitch

If you are using other versions of Laravel you can use plain PHP. You can use plain PHP in Blade. Another option switch case in laravel is to use if else approach.

@if ($login_error == 1)
    `E-mail` input is empty!

@elseif ($login_error == 2)

    `Password` input is empty!

@endif

Also You can learn more way about switch case in laravel

Posted on by:

pakainfocom profile

pakainfo

@pakainfocom

My name is Angular King. I'm a full-stack developer, entrepreneur and owner of Pakainfo. I live in India and I love to write

Discussion

pic
Editor guide
 

Hi Pakainfo

I'm Ron, I'm a dev.to mod, I look after the SQL tag and a few others.

I've noticed that you're posting articles with a high frequency and only publishing partial articles getting the reader to link back to your own website.

This is actually against our terms and conditions: dev.to/terms

As you are not really posting in good faith, ie you're not overtly interested in writing something for our community to read, I'm going to need to ask that you refrain from this behavior.

If you want to post the entire article here with the intent of sharing and engaging in the community then that's what we suggest you do.

If you continue, however, we will start to take action against your posts.