PHP code example of codebarista / laravel-workos

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

    

codebarista / laravel-workos example snippets


namespace App\Models;

use Codebarista\LaravelWorkos\Traits\HasEntitlements;
use Codebarista\LaravelWorkos\Traits\HasPermissions;
use Codebarista\LaravelWorkos\Traits\HasRoles;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasEntitlements, HasPermissions, HasRoles;

    // ...
}

// e.g. use in Laravel policies
class EntryPolicy
{
    public function viewAny(User $user): bool
    {
        return $user->hasPermissionTo('entries:view') // custom WorkOS permission
            || $user->hasRole('org-editor'); // custom WorkOS organization role
    }
    
    // ...
}

// e.g. use in Laravel gates
protected function gate(): void
{
    Gate::define('viewNova', static function (User $user) {
        return $user->hasEntitlementTo('access-dashboard'); // custom Stripe entitlement
    });
}
shell
 php artisan vendor:publish --tag="config" --provider="Codebarista\LaravelWorkos\LaravelWorkosServiceProvider"