PHP code example of inoplate / abilities

1. Go to this page and download the library: Download inoplate/abilities library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

inoplate / abilities example snippets



    use Inoplate\Abilities\BootstrapServiceProvider as BaseProvider;

    class BootstrapServiceProvider extends BaseProvider
    {
        protected function getAbilities()
        {
            // Abilities are developer defined entity. Yess!
            // You must define abilities that are available for checking
            return ['create-post', 'update-post', 'delete-post'];
        }
    }


    $user->abilities; // Retrieve user abilities
    $user->roles->abilities; // Retrieve user specific role abilities
    
    // To assign abilities, use Role. 
    // Unfortunately, we can't set abilities directly to user at the moment.
    // NOTE! Abilities assignment will override existing abilities.
    
    $role = Role::find(1);
    $role->abilities = ['new-abilities'];
    $role->save();