PHP code example of cldt / laravel-clerk

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

    

cldt / laravel-clerk example snippets



use CLDT\Clerk\Facades\Clerk;

// Get all calls
$allCalls = Clerk::calls()->all();

// Get a teams by id
$call = Clerk::teams()->find($id);

// Get all users 
$allContacts = Clerk::users([
    "from" => "1729028410",
])->all();


namespace App\Jobs\ClerkWebhooks;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use CLDT\Clerk\Models\ClerkWebhookCall;

class HandleUserCreatedWebhookJob implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;

    public ClerkWebhookCall $clerkWebhookCall;

    public function __construct(
        public ClerkWebhookCall $webhookCall
    ) {}

    public function handle()
    {
        // do your work here

        // you can access the payload of the webhook call with `$this->webhookCall->payload`
    }
}

// config/clerk.php

'webhook_jobs' => [
   'user.created' => \App\Jobs\Clerk\HandleClerkUserCreatedJob::class, // will be called when user are created
   '*' => \App\Jobs\Clerk\HandleAllWebhooks::class // will be called when any event/action comes in
],

/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    'clerk::user.created' => [
        App\Listeners\UserCreated::class,
    ],
];



namespace App\Listeners;

use Illuminate\Contracts\Queue\ShouldQueue;
use CLDT\Clerk\Models\ClerkWebhookCall;

class UserCreated implements ShouldQueue
{
    public function handle(ClerkWebhookCall $webhookCall)
    {
        // do your work here

        // you can access the payload of the webhook call with `$webhookCall->payload`
    }
}

$schedule->command('model:prune', [
    '--model' => [\CLDT\Clerk\Models\ClerkWebhookCall::class],
])->daily();
bash
php artisan vendor:publish --provider="CLDT\Clerk\ClerkServiceProvider" --tag="clerk-config"
bash
php artisan vendor:publish --provider="CLDT\Clerk\ClerkServiceProvider" --tag="clerk-migrations"
bash
php artisan migrate