The Laravel Light API package is designed to assist users in creating APIs for all Models in Laravel. With this package, you can easily generate API routes for your models, saving you time and effort.
To install the package, run the following command in your Laravel project:
$ composer require manianrezaei/laravel-light-api
Once the package is installed, you can start using it by following these steps:
-
Publish package vendors:
$ php artisan vendor:publish
then select package provider
ManianRezaei\LaravelLightApi\providers\ApiLightServiceProvider
-
Optimize the API routes using the following command:
$ php artisan optimize
-
Thats it! You now have API routes and controllers set up for all your models.
Laravel Light Api endpoint is /apilight
by default
To change the endpoint and configure the accessable models, see the config/apilight.php
.
Set the base endpoint:
'endpoint' => "/apilight",
List of models can access by api
'permissions'=>[
"usr"=> [
"model"=> \App\Models\User::class,
"allowlist" =>[
'id',
'updated_at',
'created_at'
]
]
]
"Permissions" contains an array of models that are allowed in LightAPI.
To keep the models' names hidden, you can specify an alias. In the example above, "usr" is an alias for the User model, and the endpoint for this model will be /apilight/usr.
All selectable fields should be added to the allowlist.
By default, LightAPI selects all whitelisted fields in each query.
Selected fields can be specified in the query string like this:
/apilight/usr?select=id,created_at
If you would like to contribute to this package, feel free to fork the repository on GitHub and submit a pull request. We welcome any contributions and appreciate your support.
This package is open-source and released under the MIT License. Feel free to use, modify, and distribute it as per the terms of the license.
For more information, please refer to the GitHub repository.