tadasei/backend-trashable-notifications

A package that provides stubs for soft deletable database notifications support

v1.0.0 2024-09-05 15:30 UTC

This package is auto-updated.

Last update: 2024-09-05 15:44:46 UTC


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:

  1. Form Request Configuration: Modify the generated form request (App\Http\Requests\SendNotificationRequest) to suit your application's validation rules and logic.

  2. 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.

  3. 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 Laravel Notifiable trait with this one in your desired notifiable models. For example:

    use App\Traits\Notifiable;

    This ensures that your models properly handle trashable notifications.

  4. 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-in routes/web.php or routes/api.php to make the package routes available. For example, in routes/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
    });
  5. 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.