Let's start quickly if we want to define admin areas via If Directive We start User.php in Models
public function isAdmin(): bool
{
return $this->type === 'admin';
}
in blade use isAdmin()
@if(auth()->user()->isAdmin())
For Admin
@endif
To make the code more interesting in AppServiceProvider.php
public function boot()
{
Blade::if('admin', function(){
return auth()->user()->isAdmin();
});
}
in blade use @admin
@admin
For Admin
@endadmin
We can check if the user is logged in or not by check()
public function boot()
{
Blade::if('admin', function(){
return auth()->check() && auth()->user()->isAdmin();
});
}
We can also use else
@admin
For Admin
@else
Not Admin
@endadmin
I hope you enjoyed the code.
Top comments (0)