ItSolutionStuff.com

Laravel Blade Switch Case Statement Example

By Hardik Savani β€’ April 16, 2024
Laravel

Hello Dev,

This simple article demonstrates of laravel blade switch case example. you will learn laravel switch case in blade. you can see switch case in laravel blade. you can understand a concept of laravel switch case example. Alright, let’s dive into the steps.

simple example of switch case statement in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11.

let's see bellow simple example:

Blade File Code:

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

@switch($status)

@case(1)

Active

@break

@case(2)

Wait

@break

@default

InActive

@endswitch

</body>

</html>

Controller File Code:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AjaxController extends Controller

{

/**

* Create a new controller instance.

*

* @return void

*/

public function index()

{

$status = 2;

return view('ajaxRequest', compact('status'));

}

}

Output:

Wait

I hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

Laravel Blade If Condition Example

Read Now β†’
β˜…

Laravel nl2br Blade Directive Example

Read Now β†’
β˜…

How to Create Custom Blade Directive in Laravel?

Read Now β†’
β˜…

Laravel Blade Check If Variable is Set or Not Example

Read Now β†’
β˜…

How to Write PHP Code in Laravel Blade?

Read Now β†’
β˜…

Laravel - How to Check If Array is Empty in Blade?

Read Now β†’
β˜…

Laravel - How to Get .env Variable in Blade or Controller?

Read Now β†’
β˜…

How to Create Blade File in Laravel using CMD?

Read Now β†’
β˜…

How to use Inject View in Laravel?

Read Now β†’
β˜…

Laravel Ajax Render View With Data Example

Read Now β†’