Source: www.eloquentarchitecture.com

SDKs, The Laravel Way
Each call to the builder will modify the underlying pending request. Every modification, another link in the chain, that will be sent, finally, with get().

The Ticket Model class Ticket { public function get(): Collection { $settings = config('services.connectwise'); $response = Http::baseUrl($settings['url']) ->withBasicAuth("{$settings['company_id']}+{$settings['public_key']}", $settings['private_key'], ) ->asJson() ->acceptJson() ->withHeaders(['clientId' => $settings['client_id']]) ->throw() ->get($this->url()); return new Collection($response->json()); } public function url(): string { return '/tickets'; }}app/ConnectWise/Models/Ticket.php

class Ticket { use ForwardsCalls; // url() public function newRequest(): RequestBuilder { return new RequestBuilder($this); } public function __call($method, $parameters) { return $this->forwardCallTo($this->newRequest(), $method, $parameters); }}app/ConnectWise/Models/Ticket.php$tickets = Ticket::get(); // instead of $tickets = (new RequestBuilder(new Ticket))->get(); Modifying the request

abstract class Model { use ForwardsCalls; abstract public function url(): string; // get() // newRequest() // __call() // __callStatic()}app/ConnectWise/Models/Model.phpclass Ticket extends Model { public function url(): string { return '/tickets'; }}app/ConnectWise/Models/Ticket.php
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners