PHP code example of mnabialek / laravel-authorize

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

    

mnabialek / laravel-authorize example snippets

   
   composer 

       Illuminate\Auth\AuthServiceProvider::class,
       

        Mnabialek\LaravelAuthorize\Providers\Auth::class,
        Mnabialek\LaravelAuthorize\Providers\Authorize::class,
       

    php artisan vendor:publish --provider="Mnabialek\LaravelAuthorize\Providers\Authorize"
    

    'authorize' => \App\Http\Middleware\Authorize::class,
    

    use Mnabialek\LaravelAuthorize\Contracts\Roleable as RoleableContract;
    

    implements ..., RoleableContract
    

    use \Mnabialek\LaravelAuthorize\Traits\Roleable;
    

    public function getRoles()
    {
        return $this->role ? [$this->role->slug]: [];
    }
    

\App\Http\Controllers\UserController::class => \App\Policies\UserControllerPolicy::class,
   


namespace App\Policies;

class UserControllerPolicy extends BasePolicyController
{
  protected $group = 'user';
}

'user.index',
'user.show',
'user.create',
'user.store',
'user.edit',
'user.update',
'user.destroy',

'user.index',
'user.show',
'user.store',
'user.update',
'user.destroy',

Route::group(['middleware' => ['authorize']],
  function () {        
      Route::resource('users', 'UserController');
  });

Route::show('/users/{users}/{type}', 'UserController@show')

$router->model('users', 'App\User');

public function show($user, $displayedUser, $type)
{
  if ($displayedUser->id == $user->id) {
      return true;
  }
  return false;
}

public function show($user, $displayedUser, $type)
{
  if (!$user || $displayedUser->id == $user->id) {
      return true;
  }
  return false;
}

protected function getPermissionMappings()
{
  return ['store' => 'somethingelse.store];
}