tv2regionerne / statamic-private-api
Requires
- php: ^8.2
- statamic/cms: ^4.0 || ^5.0
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.13
- nunomaduro/collision: ^8.1
- orchestra/testbench: ^9.0
- pestphp/pest: ^2.4
- pestphp/pest-plugin-watch: ^2.0
- dev-main
- v1.16.0
- v1.15.0
- v1.14.0
- v1.13.0
- v1.12.0
- v1.11.1
- v1.11.0
- v1.10.0
- v1.9.0
- v1.8.0
- v1.7.0
- v1.6.0
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.0
- dev-fix-asset-auth
- dev-feature/filters
- dev-feature/permissions
- dev-feature/v5-fixes
- dev-bug/fix_global_tests
- dev-bug/asset_url_upload
- dev-bug/globals
- dev-feature/assets-cache
- dev-feature/patch
- dev-fix/asset-entries-max-1
- dev-feature/docs
- dev-feature/allow-additional-routes-to-be-added
- dev-fix/bugs-on-update
- dev-feature/pint
- dev-feature/support-file-uploads
- dev-fix/merge-patch-data
This package is auto-updated.
Last update: 2024-10-24 10:48:16 UTC
README
Statamic Private Api is a Statamic addon that enables a private REST API.
The routes should be protected by Laravel Passport, Sanctum or similar.
Features
Add's private API seperated from the Public API build into statamic.
Uses Laravel's build in auth guards, so you may use Laravel Passport, Laravel Sanctum or something else.
Permissions will foloww the permissions assigned to the user inside of Statamic.
See https://statamic.com/addons/tv2reg/laravel-passport-ui for Laravel Passport integration into Statamic.
Limitations
The Private API uses the Statamic CP controllers.
Collection Entry revisions is not implemented.
How to Install
Run the following command from your project root:
composer require tv2regionerne/statamic-private-api
Make sure you have an 'api' guard in your config/auth.php configured.
Below example is using Laravel Passport for api authentication.
'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'passport', 'provider' => 'users', ], ],
Publish the config file:
php artisan vendor:publish --tag=private-api-config
Then, in /config/private-api.php enable the routes you would like to use, for example:
'resources' => [
'collections' => true,
'navs' => false,
'taxonomies' => false,
'assets' => false,
'globals' => false,
'forms' => false,
'users' => true,
],
How to Use
Update the config or env to enable private API's.
Configure your .env with the following values to enable the private API with a prefix on "api/private".
PRIVATE_API_ENABLED=true PRIVATE_API_ROUTE="api/private"
Addon endpoints in private API
Other addons can register their private API endpoints in the private API.
Consider below example which checks if the Private API addon is installed and then adds the addon's private API endpoints.
The routes will be protected by the same auth guard as the other Private API endpoints.
Authorisation and policies should be handled inside of the addon's controllers.
use Illuminate\Support\Facades\Route; use Tv2regionerne\StatamicPrivateApi\Facades\PrivateApi; if (class_exists(PrivateApi::class)) { PrivateApi::addRoute(function () { Route::prefix('/statamic-events/handlers') ->group(function () { Route::get('/', [Controller::class, 'index']); Route::get('{id}', [Controller::class, 'show']); Route::post('/', [Controller::class, 'store']); Route::patch('{id}', [Controller::class, 'update']); Route::delete('{id}', [Controller::class, 'destroy']); }); }); }