PHP code example of sergeybruhin / nova-supportrays

1. Go to this page and download the library: Download sergeybruhin/nova-supportrays 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/ */

    

sergeybruhin / nova-supportrays example snippets


use SergeyBruhin\NovaSupportRays\NovaSupportRays;

public function tools()
{
    return [
        new NovaSupportRays,
    ];
}

Gate::define('viewNovaSupportRays', fn ($user) => $user->isSupportStaff());

// AppServiceProvider::register()
$this->app->bind(TicketContextProvider::class, MyTicketContext::class);

final class MyTicketContext implements TicketContextProvider
{
    public function forTicket(array $ticket, ?array $client): array
    {
        // $ticket['external_ref'] / $client['external_id'] are the ids your integration sent.
        $customer = Customer::find((int) Str::after($client['external_id'] ?? '', 'customer:'));

        return [
            'sections' => [[
                'title' => 'Клиент',
                'rows' => [
                    ['label' => 'Заказов', 'value' => $customer?->orders()->count(), 'url' => "/nova/resources/customers/{$customer?->id}"],
                ],
            ]],
            'links' => [
                ['title' => 'Клиент в Nova', 'url' => "/nova/resources/customers/{$customer?->id}"],
            ],
        ];
    }
}
bash
composer migrate        # creates nova_supportrays_keys
bash
php artisan vendor:publish --provider="SergeyBruhin\NovaSupportRays\Providers\NovaSupportRaysServiceProvider" --tag=config