You are reading the Orion 1.x documentation.
Version 1.x is no longer maintained. The current version is 2.x.
TypeScript SDK
Introduction
Welcome to Orion for Laravel TypeScript SDK 1.x documentation.
How It Works
Define a model with typed attributes, set the resource name, configure the API URL, and that's it - everything is ready to work with the API ✨
import {Orion} from "@tailflow/laravel-orion/lib/orion";
import {Model} from "@tailflow/laravel-orion/lib/model";
Orion.init('https://your-api.test');
Orion.setToken('access-token-here');
export class Post extends Model<{
title: string,
body: string
}>
{
public $resource(): string {
return 'posts';
}
}
// retrieve a list of posts
const posts = await Post.$query().get();
// search for posts
const posts = await Post.$query().lookFor('some value').search();
// create a post
const newPost = await Post.$query().store({
title: 'New post' // <-- you get a nice autocompletion here, because the attributes are typed
});
console.log(newPost.$attributes.title); // <-- oh, and here as well
// retrieve a post
const post = await Post.$query().find(5);
// update a post
post.$attributes.title = 'Updated post';
await post.$save();
// or
await post.$save({title: 'Updated post'}); // <-- and here
// or
const updatedPost = await Post.$query().update(5, {
title: 'Updated title' // <-- and, of course, here
});
// delete a post
const deletedPost = await Post.$query().delete(5);
// or
await post.$destroy();
// and more: search, relationship operations, etc.
Features
- Models with typed attributes and relationships
- Support of all API operations on model and relationship resources
- Extensive search queries
- CSRF cookie fetching for seamless integration with Sanctum
Ready to dive deeper? Head to the Getting Started section and start building.