To use Blade directives like @if, @else, @elseif, and @endif in Laravel, you can follow these steps:
Open the blade template file where you want to use the directives (e.g., home.blade.php).
Use the syntax @if(condition) to start an if statement. Replace "condition" with the desired condition you want to evaluate.
Example:
@if($user->isAdmin)
{{-- Display content for an admin user --}}
@endif
Example:
@if($user->isAdmin)
<h1>Welcome, Admin!</h1>
@endif
Example:
@if($user->isAdmin)
<h1>Welcome, Admin!</h1>
@else
<h1>Welcome, Guest!</h1>
@endif
Example:
@if($user->isAdmin)
<h1>Welcome, Admin!</h1>
@elseif($user->isEditor)
<h1>Welcome, Editor!</h1>
@else
<h1>Welcome, Guest!</h1>
@endif
Example:
@if($user->isAdmin)
<h1>Welcome, Admin!</h1>
@elseif($user->isEditor)
<h1>Welcome, Editor!</h1>
@else
<h1>Welcome, Guest!</h1>
@endif
That's it! You can use these Blade directives to conditionally display content based on the conditions you specify. Remember to replace $user->isAdmin, $user->isEditor, and any other conditions with your actual variables or conditions.