PHP code example of alleyinteractive / simple-laravel-roles

1. Go to this page and download the library: Download alleyinteractive/simple-laravel-roles 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/ */

    

alleyinteractive / simple-laravel-roles example snippets


if ($user->can('edit_posts')) {
    // Cool.
}

use App\Models\Post;
use App\Models\User;
use Illuminate\Auth\Access\Response;

/**
 * Determine if the given post can be deleted by the user.
 *
 * @param  \App\Models\User  $user
 * @param  \App\Models\Post  $post
 * @return \Illuminate\Auth\Access\Response
 */
public function delete(User $user, Post $post)
{
    return $user->id === $post->user_id || $user->can('delete_others_posts')
        ? Response::allow()
        : Response::deny('You do not own this post.');
}

if ($user->can('delete_posts')) { /* ... */ }

@can('delete_posts')
  // ...
@endcan

$contributor = new Role('contributor');
if ($contributor->can('create_posts')) { /* ... */ }
bash
    php artisan vendor:publish --provider="Alley\SimpleRoles\SimpleRolesServiceProvider"