Package: example-plugin
Generated from api/packages/example-plugin
Source: api/packages/example-plugin. The sections after the README are extracted from the code on every docs build.
README
Section titled “README”A minimal ulams module that shows the package pattern end to end. It is the worked example of
the documentation page “Extending ulams → A new API package”
(front/docs-site/src/content/docs/extending/new-package.mdx).
It is not enabled: its provider is not listed in config/app.php, so the application does
not load it. Its PSR-4 entries are in api/composer.json; it has no suite in phpunit.xml
(and so does not run in CI), and its tests run by path. The test case registers the provider
itself.
What it does
Section titled “What it does”| Endpoint | Auth | What it returns |
|---|---|---|
GET /api/example-plugin/hello?name=Ada |
none | { "greeting": "Hello from the example plugin, Ada", "user_id": null } |
POST /api/admin/example-plugin/greetings { "user_id": 5 } |
auth:api + permission example-plugin_send-greeting |
the greeting sent; dispatches Ulams\ExamplePlugin\Events\GreetingSent |
- Setting:
ulams_example_plugin.greeting(default fromEXAMPLE_PLUGIN_GREETING) is registered withAdministrableConfig::registerConfigas public and editable, so it appears inGET /api/configand admins change it per tenant withPOST /api/admin/config. - Permission:
ExamplePluginPermissionEnum::SEND_GREETING, given to theadminrole byExamplePluginPermissionSeeder. - Event:
GreetingSent(User $user, string $greeting). Because the class is in theUlams\namespace and carries aUser, the notifications package stores it as a database notification of that user, and the templates package sends it on every channel that has a template registered for it.
Layout
Section titled “Layout”src/ UlamsExamplePluginServiceProvider.php config, routes, singletons Providers/SettingsServiceProvider.php AdministrableConfig::registerConfig config.php, routes.php Enums/ExamplePluginPermissionEnum.php Events/GreetingSent.php Services/GreetingService.php (+ Contracts/) Http/Controllers/... (+ Swagger/ interfaces with the OpenAPI annotations) Http/Requests/Admin/SendGreetingRequest.php authorize() checks the permission Http/Resources/GreetingResource.phpdatabase/seeders/ExamplePluginPermissionSeeder.phptests/ TestCase, API tests, tenant isolation testEnabling it
Section titled “Enabling it”- Add
Ulams\ExamplePlugin\UlamsExamplePluginServiceProvider::classto the “Package Service Providers” inapi/config/app.php. - Seed the permission, per tenant:
php artisan db:seed --class="Ulams\ExamplePlugin\Database\Seeders\ExamplePluginPermissionSeeder" --domain=<slug>.localhost - Optional: add
base_path('packages/example-plugin/src')to the annotation paths inconfig/l5-swagger.phpto publish its endpoints in the OpenAPI document.
docker compose -f api/docker-compose.yml exec api bash -c \ "DB_HOST=postgres DB_DATABASE=test DB_USERNAME=default DB_PASSWORD=secret ./vendor/bin/phpunit packages/example-plugin/tests"API endpoints
Section titled “API endpoints”| Method | Path | Auth | Action |
|---|---|---|---|
GET |
/api/example-plugin/hello |
HelloApiController@hello |
|
POST |
/api/admin/example-plugin/greetings |
yes | GreetingAdminApiController@send |
Permissions
Section titled “Permissions”| Permission | Seeded for roles | Constant |
|---|---|---|
example-plugin_send-greeting |
admin | ExamplePluginPermissionEnum::SEND_GREETING |
Settings
Section titled “Settings”Registered with AdministrableConfig::registerConfig (editable in the admin panel under Configuration → Settings).
| Key | Rules | Public | Read-only |
|---|---|---|---|
ulams_example_plugin.greeting |
required, string, max:200 | yes |
Events
Section titled “Events”| Event | Description | Notification templates |
|---|---|---|
GreetingSent |
Dispatched when an admin sends a greeting to a user. The class lives in the Ulams\ namespace and carries a User, so the notifications package stores it as a database notification of that user and the templates package can send it on any channel an admin has a template for. |
Artisan commands
Section titled “Artisan commands”None.
Scheduled jobs
Section titled “Scheduled jobs”None.
Environment variables read
Section titled “Environment variables read”EXAMPLE_PLUGIN_GREETING