Laravel blade if multiple conditions example

Laravel blade if multiple conditions example; In this tutorial, you will learn how to use multiple if conditions in Laravel blade file. Many times we need to update our code with (and) operator or (or) operator for giving access to a specific one.

You can write multiple conditions (&& or || statement) in the if statement with laravel 5, laravel 6, laravel 7, laravel 8, and laravel 9 apps.

Example 1:

Here we are using the if multiple conditions with and operator.

<!DOCTYPE html>
<html>
<head>
    <title>Laravel Blade If Multiple Conditions Example</title>
</head>
<body>
    @if(auth()->user()->hasRole('admin') && $active == 1)
      <p>Admin User</p>
    @endif
</body>
</html>

Example 2:

In this example, we have updated the code with if multiple with or operator.

<!DOCTYPE html>
<html>
<head>
    <title>Laravel Blade If Multiple Conditions Example</title>
</head>
<body>
    @if(auth()->user()->hasRole('super-admin') && auth()->user()->hasRole('admin') )
      <p>Admin Access</p>
    @endif
</body>
</html>

Hope these examples help you.

Leave a Comment