Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AbehoM's avatar

Create a custom API wrapper

This is not directly related to Laravel but I'm going to use in a Laravel application.

I need to create a wrapper to an API and I wanted to create something similar to Eloquent.

For example, this API has an endpoint called plans, I wanted to create a wrapper to be something like Laravel models and Eloquent works:

$plan = new Plan;
$plan->...;
$plan->save(); // it would call the post in the endpoint
// or ...
Plan::create([]);
Plan::get('pl-299541'); // it would call get in the endpoint

I want to use Guzzle to make the requests easier.

I was wondering, how can I make something (chaining, static calls, etc) like this (as Laravel does with Eloquent)?

Thank you.

0 likes
0 replies

Please or to participate in this conversation.