1. Go to this page and download the library: Download lion9966/think-permission 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/ */
lion9966 / think-permission example snippets
use lion9966\Permission\Model\Permission;
// 创建一条可查看首页的权限
Permission::create(['name' => 'home']);
use lion9966\Permission\Model\Role;
// 创建一个名为编辑的角色
Role::create(['name' => 'writer']);
use lion9966\Permission\Model\User;
// 创建一个名为lion9966的用户
User::create(['name' => 'lion9966']);
namespace app\model;
use think\Request;
use lion9966\Permission\Contract\UserContract;
class User implements UserContract
{
use \lion9966\Permission\Traits\User;
}
namespace app\middleware;
use think\Request;
use app\model\User;
class Auth
{
public function handle($request, \Closure $next)
{
$uid = 1;
$user = User::find($uid);
$request->user = $user;
return $next($request);
}
}