Laravel Blade Switch Case Statement Example
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 and laravel 10.
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...

Hardik Savani
I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Blade If Condition Example
- Laravel nl2br Blade Directive Example
- How to Create Custom Blade Directive in Laravel?
- Laravel - How to check if isset variable in Blade?
- How to Write PHP Code in Laravel Blade?
- Laravel - How to Check If Array is Empty in Blade?
- Laravel - How to get .env variable in blade or controller?
- How to Create Blade View File using Command Line in Laravel?
- How to use Inject View in Laravel?
- Laravel ajax render view with data example