Laravel Orion
The simplest way to create REST API with Laravel
Simple yet powerful
Fully featured REST API for your Eloquent models and relationships with the simplicity of Laravel as you love it.
Easy to use and learn
Utilizes standard Laravel features such as Request classes, Policies and API Resources.
SDK and OpenAPI specs
TypesScript SDK and OpenAPI specifications out of the box.
# As easy as 1, 2, 3
- Define controllers
<?php
namespace App\Http\Controllers\Api;
use App\Models\Post;
use Orion\Http\Controllers\Controller;
class PostsController extends Controller
{
/**
* Fully-qualified model class name
*/
protected $model = Post::class; // or "App\Models\Post"
}
<?php
namespace App\Http\Controllers\Api;
use App\Models\Post;
use Orion\Http\Controllers\RelationController;
class PostTagsController extends RelationController
{
/**
* Fully-qualified model class name
*/
protected $model = Post::class; // or "App\Models\Post"
/**
* Name of the relationship as it is defined on the Post model
*/
protected $relation = 'tags';
}
ATTENTION
Make sure to have policy (opens new window) created and registered for the model you are exposing via the API or consider using DisableAuthorization
trait (only for local testing) to avoid getting 403 error, if the policy is not registered or incorrect.
- Register routes
<?php
use Illuminate\Support\Facades\Route;
use Orion\Facades\Orion;
use App\Http\Controllers\PostsController;
use App\Http\Controllers\PostTagsController;
Route::group(['as' => 'api.'], function() {
Orion::resource('posts', PostsController::class)->withSoftDeletes();
Orion::morphToManyResource('posts', 'tags' , PostTagsController::class);
});
- Enjoy a fully featured REST API 😌
+--------+-----------+-------------------------------------------------+----------------------------------------+---------------------------------------------------------------------------+-------------------------------------------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+-------------------------------------------------+----------------------------------------+---------------------------------------------------------------------------+-------------------------------------------------+
| | GET|HEAD | api/posts | api.posts.index | App\Http\Controllers\Api\PostsController@index | api |
| | POST | api/posts/search | api.posts.search | App\Http\Controllers\Api\PostsController@index | api |
| | POST | api/posts | api.posts.store | App\Http\Controllers\Api\PostsController@store | api |
| | GET|HEAD | api/posts/{post} | api.posts.show | App\Http\Controllers\Api\PostsController@show | api |
| | PUT|PATCH | api/posts/{post} | api.posts.update | App\Http\Controllers\Api\PostsController@update | api |
| | DELETE | api/posts/{post} | api.posts.destroy | App\Http\Controllers\Api\PostsController@destroy | api |
| | POST | api/posts/{post}/restore | api.posts.restore | App\Http\Controllers\Api\PostsController@restore | api |
| | POST | api/posts/batch | api.posts.batchStore | App\Http\Controllers\Api\PostsController@batchStore | api |
| | PATCH | api/posts/batch | api.posts.batchUpdate | App\Http\Controllers\Api\PostsController@batchUpdate | api |
| | DELETE | api/posts/batch | api.posts.batchDestroy | App\Http\Controllers\Api\PostsController@batchDestroy | api |
| | POST | api/posts/batch/restore | api.posts.batchRestore | App\Http\Controllers\Api\PostsController@batchRestore | api |
| | GET|HEAD | api/posts/{post}/tags | api.posts.relation.tags.index | App\Http\Controllers\Api\PostTagsController@index | api |
| | POST | api/posts/{post}/tags/search | api.posts.relation.tags.search | App\Http\Controllers\Api\PostTagsController@index | api |
| | POST | api/posts/{post}/tags | api.posts.relation.tags.store | App\Http\Controllers\Api\PostTagsController@store | api |
| | GET|HEAD | api/posts/{post}/tags/{tag} | api.posts.relation.tags.show | App\Http\Controllers\Api\PostTagsController@show | api |
| | PUT|PATCH | api/posts/{post}/tags/{tag} | api.posts.relation.tags.update | App\Http\Controllers\Api\PostTagsController@update | api |
| | DELETE | api/posts/{post}/tags/{tag} | api.posts.relation.tags.destroy | App\Http\Controllers\Api\PostTagsController@destroy | api |
| | POST | api/posts/{post}/tags/batch | api.posts.relation.tags.batchStore | App\Http\Controllers\Api\PostTagsController@batchStore | api |
| | PATCH | api/posts/{post}/tags/batch | api.posts.relation.tags.batchUpdate | App\Http\Controllers\Api\PostTagsController@batchUpdate | api |
| | DELETE | api/posts/{post}/tags/batch | api.posts.relation.tags.batchDestroy | App\Http\Controllers\Api\PostTagsController@batchDestroy | api |
| | POST | api/posts/{post}/tags/attach | api.posts.relation.tags.attach | App\Http\Controllers\Api\PostTagsController@attach | api |
| | DELETE | api/posts/{post}/tags/detach | api.posts.relation.tags.detach | App\Http\Controllers\Api\PostTagsController@detach | api |
| | PATCH | api/posts/{post}/tags/sync | api.posts.relation.tags.sync | App\Http\Controllers\Api\PostTagsController@sync | api |
| | PATCH | api/posts/{post}/tags/toggle | api.posts.relation.tags.toggle | App\Http\Controllers\Api\PostTagsController@toggle | api |
| | PATCH | api/posts/{post}/tags/{tag}/pivot | api.posts.relation.tags.pivot | App\Http\Controllers\Api\PostTagsController@updatePivot | api |