PHP code example of laravel-admin-utils / authorization

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

    

laravel-admin-utils / authorization example snippets


  namespace App\Admin\Actions;
  
  use Elegant\Utils\Actions\Response;
  use Elegant\Utils\Actions\RowAction;
  use Illuminate\Database\Eloquent\Model;
  use Illuminate\Support\Facades\DB;
  
  class Replicate extends RowAction
  {
      /**
       * @var string
       */
      protected $method = 'POST';
  
      /**
       * @return array|null|string
       */
      public function name()
      {
          return 'replicate';
      }
  
      // getHandleUrl() or handle(Model $model) choose one of the two
  
      //========================if permission judgment is /    } catch (\Exception $exception) {
      //        return $this->response()->error('replication failed!: ' . $exception->getMessage() . ')';
      //    }
  
      //    return $this->response()->success('replication successful!')->refresh();
      //}
      
      /**
       * @return void
       */
      public function dialog()
      {
          $this->question('confirm copy?');
      }
  }
  

  
  use Elegant\Utils\Http\Controllers\HandleController;
  
  class UserController extends AdminController
  {
      public function replicate($id)
      {
          // If permission judgment is         } catch (\Exception $exception) {
              return $this->response()->error("replication failed!: {$exception->getMessage()}")->send();
          }
          return $this->response()->success('replication successful!')->refresh()->send();

          // If you don't need permission judgment, handle it in App\Admin\Actions\Replicate::handle() logic
          //return $this->handleAction();
      }
  }
  
shell
php artisan vendor:publish --provider="Elegant\Utils\Authorization\AuthorizationServiceProvider"
shell
php artisan authorization:init