PHP code example of relaxsd / laravel-model-gates

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

    

relaxsd / laravel-model-gates example snippets


use Relaxsd\Gate\ModelGate;

class ProjectGate extends ModelGate {

    public function members()
    {
        if (\Gate::allows('indexForProject', [\App\Member::class, $this->entity])) {
            return $this->entity->members;
        }
        return new \Illuminate\Database\Eloquent\Collection(); // Not authorized: return an empty collection instead. 
    }

}



use Relaxsd\Gate\ModelGateTrait;

class Project extends \Eloquent {

    use ModelGateTrait;

    protected $gate = 'ProjectGate';

}

    return $project->gate()->members; // Only the members we're allowed to see