PHP code example of glhd / linearavel

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

    

glhd / linearavel example snippets


use Glhd\Linearavel\Facades\Linear;

$viewer = Linear::viewer() // "viewer" is the name of the GraphQL query
    ->with('organization', 'id', 'name') // `with` lets you quickly retrieve nested fields
    ->get('id', 'name', 'active', 'avatarUrl', 'timezone'); // `get` defines the fields to retrieve

assert($viewer instanceof Glhd\Linearavel\Data\User);
assert($viewer->name === 'Chris Morrell');
assert($viewer->organization instanceof Glhd\Linearavel\Data\Organization);
assert($viewer->organization->name === 'InterNACHI');

$teams = linear()->teams(first: 10)->get();

use Glhd\Linearavel\Data\Enums\PaginationOrderBy;
use Glhd\Linearavel\Requests\Inputs\DateComparatorInput;
use Glhd\Linearavel\Requests\Inputs\IssueFilterInput;

$issues = linear()
    ->issues(
        filter: new IssueFilterInput(
            createdAt: new DateComparatorInput(gt: now()->subWeek()),
        ),
        orderBy: PaginationOrderBy::updatedAt,
        first: 50,
    )
    ->get();

use Glhd\Linearavel\Requests\Inputs\IssueCreateInput;

$result = linear()
    ->issueCreateMutation(new IssueCreateInput(
        teamId: $team->id,
        title: 'Something is broken',
        description: 'It broke.',
    ))
    ->get('success', 'issue.id', 'issue.identifier', 'issue.url');

assert($result->success === true);
echo $result->issue->url;

$response = linear()->viewer()->response('id', 'name');

$response->status(); // 200
$response->header('X-RateLimit-Requests-Remaining');
$response->resolve(); // Glhd\Linearavel\Data\User

use Glhd\Linearavel\Exceptions\LinearRequestException;

try {
    linear()->issue($id)->get();
} catch (LinearRequestException $exception) {
    $exception->messages(); // Collection of human-readable messages
    $exception->codes();    // Collection of Linear error codes, e.g. "RATELIMITED"
    $exception->errors();   // The raw GraphQL errors
    $exception->getResponse(); // The Saloon response
}

use Glhd\Linearavel\Data\Contracts\OrganizationInviteDetailsPayload;
use Glhd\Linearavel\Data\OrganizationInviteFullDetailsPayload;

$details = linear()->organizationInviteDetails($id)->get();

assert($details instanceof OrganizationInviteDetailsPayload);

if ($details instanceof OrganizationInviteFullDetailsPayload) {
    echo $details->organizationName;
}
shell
php artisan vendor:publish --tag=linearavel-config