Search
 
SCRIPT & CODE EXAMPLE
 

PHP

custom blade if directive

1-> AppServiceProvider.php
	  public function boot()
    {
        Paginator::useBootstrap();

        Blade::if('admin',function (){
             // return auth()->check() && auth()->user()->isAdmin();
             return auth()->check() && auth()->user()->role === 'admin';
        });
    }
    
2-> now you can use in blade file
	@admin
    @else
    @endadmin
=============================================================

if you want to use isAdimin method 
you can create method in model file

User.php
 public function isAdmin():bool{
        return $this->role === 'admin';
    }
======================================================================
Comment

PREVIOUS NEXT
Code Example
Php :: map array php 
Php :: phpmailer doesnt work on infinityfree 
Php :: Route [login] not defined.Route [login] not defined. 
Php :: if post checked category wordpress 
Php :: setup phpmyadmin to show create statement query 
Php :: laravel roles and permissions 
Php :: Pure Intersection Types - PHP 8.1 
Php :: insert views laravel database 
Php :: php update sql database from form 
Php :: Update Custom Cart Count (or any HTML) after AJAX Add to Cart in WooCommerce 
Php :: login with email or username codeigniter 4 
Php :: numberformater php format to k and m 
Php :: laravel where condition with if 
Php :: remove php 
Php :: php config file 
Php :: laravel get current user id 
Php :: laravel log error 
Php :: php array remove the last element 
Php :: how to extract code from controller to helpers or other method in laravel 
Php :: session variable 
Php :: laravel use npm package 
Php :: php iframe add content 
Php :: what is the use of migration file in laravel 
Php :: php barcode generator 
Php :: get image field in custom post type category taxonomy 
Php :: laravel repository design pattern 
Php :: The Laravel installer requires PHP 7.3.0 or greater. Please use "composer create-project laravel/laravel" instead. 
Php :: displaying dates using php code 
Php :: Generate Laravel Migrations from an existing database 
Php :: how do i use php read excel file 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =