PHP code example of leap-lyhour / lighthouse-graphql-sanctum-auth

1. Go to this page and download the library: Download leap-lyhour/lighthouse-graphql-sanctum-auth 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/ */

    

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');
bash
php artisan vendor:publish --tag=lighthouse-sanctum-auth-config