1. Go to this page and download the library: Download dniccum/linear-sdk 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/ */
dniccum / linear-sdk example snippets
use Dniccum\Linear\Concerns\HasLinearConnection;
class User extends Authenticatable
{
use HasLinearConnection;
}
$user->hasLinearConnection(); // bool
$user->linearConnection; // LinearConnection|null
$user->linearDestination; // LinearDestination|null (team, project, state, labels, ...)
$user->linearClient(); // talk to Linear as this owner
$user->disconnectLinear();
use Dniccum\Linear\Concerns\CreatesLinearIssues;
class SupportRequest extends Model
{
use CreatesLinearIssues;
protected $appends = ['linear_issue_url', 'linear_issue_identifier', 'linear_sync_status'];
public function user(): BelongsTo { /* ... */ }
}
$request->sendToLinear(); // file it now (manual mode)
$request->sendToLinear(['title' => 'Custom title']);
$request->retryLinear(); // retry a failed sync
$request->commentOnLinear('Customer replied.'); // comment on its issue
public function linearEvents(): array
{
return ['created', 'updated', 'deleted'];
}
public function linearOwner(): ?Model // who owns the connection (default: $this->user)
public function linearTitle(): string // issue title
public function linearDescription(): string // issue description (Markdown)
public function linearComment(string $event, array $context = []): string
public function linearDestinationOverride(): ?LinearDestination // use a different team/project for this model
use Dniccum\Linear\Events\{LinearIssueCreated, LinearIssueFailed, LinearCommentDelivered};
Event::listen(LinearIssueCreated::class, fn ($e) => logger($e->link->linear_issue_url));
use Dniccum\Linear\Facades\Linear;
Linear::resolveOwnerUsing(fn (Request $request) => $request->user()->currentTeam);
Linear::authorizeUsing(fn (Request $request, Model $owner) => $request->user()->can('manage-integrations', $owner));
// config/linear.php (or LINEAR_BACK_LABEL / LINEAR_BACK_URL in .env)
'back' => [
'enabled' => true, // false hides the link
'label' => 'Back', // text, or a translation key such as 'linear.back'
'url' => '/dashboard', // a route name ('dashboard'), a path or a full URL
],
use Dniccum\Linear\Facades\Linear;
Linear::backUsing(fn (Model $owner) => route('teams.show', $owner));
// config/linear.php (or LINEAR_LOGIN_ROUTE in .env)
'login_route' => 'login', // a route name
// 'login_route' => '/sign-in', // a path
// 'login_route' => 'https://sso.example.com/login', // a full URL
// 'login_route' => null, // disable: requests are refused with a 403 instead
use Dniccum\Linear\Data\IssuePayload;
use Dniccum\Linear\Exceptions\LinearApiException;
use Dniccum\Linear\Facades\Linear;
it('files a Linear issue for a new support request', function () {
$linear = Linear::fake();
$request = SupportRequest::factory()->create();
$linear->assertIssueCreated(fn (IssuePayload $payload) => $payload->title === $request->subject);
});
Linear::fake()->failWith('createIssue', new LinearApiException('Linear is down', LinearApiException::TRANSIENT), times: 2);