tadasei / backend-trashable-notifications
A package that provides stubs for soft deletable database notifications support
Requires
- php: ^8.1.0
- illuminate/console: ^9.0|^10.0|^11.0
- illuminate/filesystem: ^9.0|^10.0|^11.0
- illuminate/support: ^9.0|^10.0|^11.0
- illuminate/validation: ^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^8.0
- phpstan/phpstan: ^1.10
README
This package provides stubs for managing trashable (soft deletable) database notifications in the backend of a Laravel application. It simplifies common Index, Store, Update, and Delete notification operations by providing pre-defined structures.
Features
- Quickly generate trashable database notifications management files and handling logic.
- Customize and extend generated code to fit your project's needs.
- Improve development efficiency by eliminating repetitive tasks.
Installation
Install the package via Composer by running:
composer require tadasei/backend-trashable-notifications --dev
Usage
Publishing Trashable Notifications Management Utilities
To publish the utilities, run:
php artisan trashable-notifications:install
Configuration
After publishing the utilities, follow these steps to complete the configuration:
-
Form Request Configuration: Modify the generated form request (
App\Http\Requests\SendNotificationRequest
) to suit your application's validation rules and logic. -
Policy Configuration: Update the generated policy (
App\Policies\DatabaseNotificationPolicy
) to control access to notification management operations, ensuring it aligns with your project's authorization system. -
Notifiable Trait Replacement: The package provides a custom
Notifiable
trait, which will be published along with the other management utilities. You must replace the built-in LaravelNotifiable
trait with this one in your desired notifiable models. For example:use App\Traits\Notifiable;
This ensures that your models properly handle trashable notifications.
-
Routes Registration: The
routes/resources/notification.php
file is generated as part of the management utilities. You must register this file in your application's built-inroutes/web.php
orroutes/api.php
to make the package routes available. For example, inroutes/api.php
:<?php require __DIR__ . '/resources/notification.php';
The generated routes are protected by the
auth:sanctum
middleware by default. If your project uses a different authentication guard, you may need to update the middleware to fit your authentication system.Route::middleware('auth:your_guard')->group(function () { // Register routes });
-
Running the Migration: The package generates a migration as part of the utilities. You need to run this migration to set up the necessary database structure for managing trashable notifications. Use the following Artisan command:
php artisan migrate
These steps are necessary to ensure that the package integrates smoothly with your application's existing structure.
Further Customization
The generated code serves as a starting point. You can further extend and customize it to fit your project’s needs.
Contributing
Contributions are welcome! If you have suggestions, bug reports, or feature requests, please open an issue on the GitHub repository.
License
This package is open-source software licensed under the MIT license.