<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
leap-lyhour / lighthouse-graphql-sanctum-auth example snippets
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
use Laravel\Sanctum\HasApiTokens;
use LeapLyhour\LighthouseGraphQLSanctumAuth\Support\Traits\HasDevices;
class User extends Authenticatable
{
use HasApiTokens, HasRoles, HasDevices;
// ... your code
}
use LeapLyhour\LighthouseGraphQLSanctumAuth\Support\Helpers\AuthHelper;
use LeapLyhour\LighthouseGraphQLSanctumAuth\Support\Helpers\PermissionHelper;
// Check authentication
// ពិនិត្យ authentication
if (AuthHelper::check()) {
$user = AuthHelper::user();
}
// Check role
// ពិនិត្យ role
if (AuthHelper::hasRole('admin')) {
// User is admin
}
// Check permission
// ពិនិត្យ permission
if (AuthHelper::hasPermission('edit posts')) {
// User can edit posts
}
// Find or create role
// រក ឬបង្កើត role
$role = PermissionHelper::findOrCreateRole('editor');