PHP code example of jeroen-g / laravel-auth

1. Go to this page and download the library: Download jeroen-g/laravel-auth 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/ */

    

jeroen-g / laravel-auth example snippets


if(Auth::can('edit'))
{
	// show a form to edit stuff.
}

if(Auth::is('Moderator'))
{
	// Show a form to edit stuff, if the 'Moderator' role has the 'edit' permission.
}

Auth::isAdmin();

Route::filter('auth.admin', function()
{
	if ( ! Auth::isAdmin()) return Redirect::to('login');
});

Auth::allRoles();

Auth::allPermissions();

Auth::allUsers();

//Example of both optional parameter
Auth::allUsers('json', true);

Auth::giveRole('Member', 2);

Auth::givePermission('edit', 2);

Auth::giveRolePermission('edit', 'Admin');

Auth::roleCan('Admin', 'edit');

Auth::takeRole('Member', 2);

Auth::takePermission('edit', 2);

Auth::takeRolePermission('edit', 'Admin');

Auth::roleExists('Admin');

Auth::permissionExists('edit');

Auth::userExists(2);

// Name, description, level (any number)
Auth::addRole('Admin', 'One Role To Rule Them All', 10);

// Name, description
Auth::addPermission('edit', 'Ability to edit stuff');

// Username, password, email
Auth::addUser('Jeroen', 'password123', '[email protected]');

Auth::deleteRole('Moderator');

Auth::deletePermission('edit', true);

Auth::deleteUser(2);