1. Go to this page and download the library: Download jellis/check 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/ */
namespace App\Roles;
use Jellis\Check\Roles\Base;
class Member extends Base {
protected $permissions = [
'post' => [
'index', 'view', 'create', 'store', 'view', 'edit:own', 'update:own',
],
];
}
namespace App\Models;
use Jellis\Check\RouteAwareModel;
class Post extends RouteAwareModel
{
protected $table = 'posts';
...
/**
* This is to check against a given model
*/
public function allowOwnOnly()
{
return $this->user_id == \Auth::id();
}
/**
* This is to restrict things coming out of the database
*/
public function restrictOwnOnly(Builder $builder)
{
$builder->where('user_id', Auth::id());
}
}
class User extends Model {
...
public function getRole()
{
return $this->role; // Or however you determine what a user's role is right now
}
...
}
class PostController extends Controller {
public function index()
{
// You could check stuff here if you need to
$myThing = Check::can('my.thing');
// Or you can do a contextual check, say, on a post
$post = Post::find(1);
if (Check::can('post.edit', $post)) {
// Do some thing
}
// In this instance, let's pass it to the view
$posts = Post::all();
return view('post.index', compact('posts'));
}
}
class SuperAdmin extends Base
{
/**
* Can do all the things all the time
*
* @param string $action
* @param Model $model
* @return bool
*/
public function check($action, Model $model = null)
{
return true;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.