kindharika / laravel-api-starter
A Laravel API starter package with service layer, datatable macro, UUID models, FCM notifications, and scaffold generators.
Requires
- php: ^8.2
- illuminate/console: ^11.0 || ^12.0 || ^13.0
- illuminate/database: ^11.0 || ^12.0 || ^13.0
- illuminate/support: ^11.0 || ^12.0 || ^13.0
- ramsey/uuid: ^4.0
Requires (Dev)
- orchestra/testbench: ^9.0 || ^10.0 || ^11.0
- phpunit/phpunit: ^10.0 || ^11.0
This package is not auto-updated.
Last update: 2026-05-22 02:41:05 UTC
README
A Laravel package that brings the best of the laravel-template API architecture into a reusable, modern, and maintainable form. Supports Laravel 11.x, 12.x, and 13.x.
Features
- UUID-based models out of the box (v4 by default, configurable)
- Unified JSON response envelope with pagination metadata
- Service layer pattern (BaseService, BaseServiceInterface)
- Base API Controller (BaseApiController)
- Datatable macro (search, sort, filter, date-range on Eloquent Builder)
- Firebase Cloud Messaging (FCM) infrastructure (Channel, Notification, Trait)
- Artisan scaffold generators (model, service, controller, request, migration, resource)
- Auto-discovery via Composer extras
Installation
composer require kindharika/laravel-api-starter
Or add via path repository for local development:
{
"repositories": [
{
"type": "path",
"url": "./package/laravel-api-starter"
}
]
}
Publish Config
php artisan vendor:publish --tag=api-starter-config
Usage
Base classes
Your models should extend BaseModel:
use Kindharika\ApiStarter\Base\BaseModel; class Post extends BaseModel { protected $table = 'posts'; }
Your controllers should extend BaseApiController:
use Kindharika\ApiStarter\Base\BaseApiController; class PostController extends BaseApiController { // use sendSuccess() / sendError() }
Your services should extend BaseService and implement BaseServiceInterface:
use Kindharika\ApiStarter\Base\BaseService; use Kindharika\ApiStarter\Base\BaseServiceInterface; class PostService extends BaseService implements BaseServiceInterface { // implements dataTable, getById, create, update, delete }
Datatable macro
Once installed, the macro is available on any query builder:
$posts = Post::datatable($request->all())->paginate(15);
Scaffolding
Generate a full resource scaffold with one command:
php artisan api:scaffold Post
This generates:
app/Models/Post.phpapp/Http/Controllers/PostController.phpapp/Http/Requests/Post/StorePost.phpapp/Http/Requests/Post/UpdatePost.phpapp/Services/Post/PostService.phpapp/Services/Post/PostServiceInterface.phpapp/Http/Resources/PostResource.php- Database migration
Or generate individually:
php artisan api:make-model Post php artisan api:make-controller PostController --model=Post php artisan api:make-service PostService --model=Post php artisan api:make-request Post php artisan api:make-migration Post php artisan api:make-resource Post
Firebase Notification
Use the trait in your service or notification class:
use Kindharika\ApiStarter\Traits\FirebaseNotification; class YourService { use FirebaseNotification; public function notify($user) { $this->sendNotification($user, 'Title", "Body", "INFO"); } }
Configuration
config/api-starter.php:
return [ 'namespace' => 'App', 'uuid_version' => 4, 'fcm' => [ 'enabled' => true, 'server_key' => env('FCM_SERVER_KEY'), 'endpoint' => 'https://fcm.googleapis.com/fcm/send', ], 'datatable' => [ 'per_page' => 15, 'default_sort_column' => 'created_at', 'default_sort_direction' => 'desc', ], ];
Upgrading from Template
If you were previously using the laravel-template as-is, migrate by:
composer require kindharika/laravel-api-starter- Replace
AppModelwithKindharika\ApiStarter\Base\BaseModel - Replace
AppAuthenticatablewithKindharika\ApiStarter\Base\BaseAuthenticatable - Replace
AppServicewithKindharika\ApiStarter\Base\BaseService - Replace
ApiControllerwithKindharika\ApiStarter\Base\BaseApiController - Replace
ResponseServicewithKindharika\ApiStarter\Base\ResponseService - Remove
DatatableServiceProvider— the macro is registered automatically now - Use
api:scaffoldto generate new resources instead of manual stubs
License
MIT