1. Go to this page and download the library: Download zynqa/filament-freeagent 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/ */
zynqa / filament-freeagent example snippets
use Zynqa\FilamentFreeAgent\Models\Concerns\HasFreeAgentContact;
class User extends Authenticatable
{
use HasFreeAgentContact;
// ... rest of your model
}
// app/Settings/GeneralSettings.php
use Spatie\LaravelSettings\Settings;
class GeneralSettings extends Settings
{
// ... existing fields
public ?string $freeagent_client_id;
public ?string $freeagent_client_secret;
public ?string $freeagent_api_url;
public ?string $freeagent_oauth_url;
public static function group(): string
{
return 'general';
}
}
// database/settings/xxxx_create_free_agent_settings.php
public function up(): void
{
$this->migrator->add('general.freeagent_client_id', env('FREEAGENT_CLIENT_ID'));
$this->migrator->add('general.freeagent_client_secret', env('FREEAGENT_CLIENT_SECRET'));
$this->migrator->add('general.freeagent_api_url', env('FREEAGENT_API_URL', 'https://api.freeagent.com/v2'));
$this->migrator->add('general.freeagent_oauth_url', env('FREEAGENT_OAUTH_URL', 'https://api.freeagent.com'));
}
// Super admins see all
if ($user->hasRole('super_admin')) {
return $query; // All invoices
}
// Regular users must have contact linked
$contactId = $user->getFreeAgentContactId();
if (!$contactId) {
return $query->whereRaw('1 = 0'); // Empty
}
// Filter by contact
return $query->forContact($contactId);
// View any invoices (if has contact or is admin)
auth()->user()->can('viewAny', FreeAgentInvoice::class);
// View specific invoice (must match contact)
auth()->user()->can('view', $invoice);
// Download PDF (same as view)
auth()->user()->can('downloadPdf', $invoice);
// No create/update/delete (read-only resource)
auth()->user()->cannot('create', FreeAgentInvoice::class);
$service = app(FreeAgentService::class);
// Get invoices with filters
$invoices = $service->getInvoices($user, [
'contact' => 'https://api.freeagent.com/v2/contacts/123',
'view' => 'recent',
'from_date' => '2024-01-01',
'to_date' => '2024-12-31',
]);
// Get single invoice
$invoice = $service->getInvoice($user, $invoiceId);
// Download PDF (returns binary content)
$pdfContent = $service->getInvoicePdf($user, $invoiceId);
// Get contacts
$contacts = $service->getContacts($user);
// Get projects
$projects = $service->getProjects($user, [
'contact' => 'https://api.freeagent.com/v2/contacts/123'
]);
$oauthService = app(FreeAgentOAuthService::class);
// Get authorization URL
$url = $oauthService->getAuthorizationUrl($state);
// Handle callback (stores with user_id = 1)
$token = $oauthService->handleCallback($code, $user);
// Get valid system token (auto-refreshes if expired)
$token = $oauthService->getValidAccessToken(); // No user param needed
// Revoke system token
$oauthService->revokeToken();