All Projects → williamcruzme → laravel-notification-settings

williamcruzme / laravel-notification-settings

Licence: MIT license
🔒 A Laravel package that allows you to check the notification settings before send them.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-notification-settings

Control Uwp
🌚🌓Alternative Control Panel for Windows 10
Stars: ✭ 237 (+746.43%)
Mutual labels:  settings
SimpleConfig
No description or website provided.
Stars: ✭ 22 (-21.43%)
Mutual labels:  settings
PushNotifications
Push Notification using Embarcadero Rad Studio Tokyo 10.2.3 on Android and Apple Devices written in C++ and Delphi
Stars: ✭ 12 (-57.14%)
Mutual labels:  notification
android-rxlocationsettings
An easy way to ensure the settings before requesting location using RxJava.
Stars: ✭ 43 (+53.57%)
Mutual labels:  settings
SplitShare
Shamir's Secret Sharing Algorithm implementation in golang combined with PGP and a mail delivery system
Stars: ✭ 31 (+10.71%)
Mutual labels:  notification
Compose-Settings
Android #JetpackCompose Settings library
Stars: ✭ 188 (+571.43%)
Mutual labels:  settings
Laravel App Settings
Store settings in database with a manager UI for your Laravel app
Stars: ✭ 220 (+685.71%)
Mutual labels:  settings
SPLarkController
Custom transition between controllers. Settings controller for your iOS app.
Stars: ✭ 967 (+3353.57%)
Mutual labels:  settings
mac-notification-sys
✉️ A simple wrapper to deliver or schedule macOS Notifications in Rust
Stars: ✭ 73 (+160.71%)
Mutual labels:  notification
plaster
Application config settings abstraction layer.
Stars: ✭ 19 (-32.14%)
Mutual labels:  settings
Dashi
💯 Get a notification in Slack every time someone asks you to check some code on Github or Bitbucket.
Stars: ✭ 29 (+3.57%)
Mutual labels:  notification
x-notification
Declarative Browser Notification as Web Components.
Stars: ✭ 37 (+32.14%)
Mutual labels:  notification
shoppers
Flutter E-Commerce App using Firebase, Razorpay and Stripe
Stars: ✭ 94 (+235.71%)
Mutual labels:  notification
Django Dynamic Preferences
Dynamic global and instance settings for your django project
Stars: ✭ 238 (+750%)
Mutual labels:  settings
dotfiles
To make life easier when setting up a new computer
Stars: ✭ 31 (+10.71%)
Mutual labels:  settings
Settings View
🔧 Edit Atom settings
Stars: ✭ 226 (+707.14%)
Mutual labels:  settings
notification-sounds
Makes a sound when a notification is shown
Stars: ✭ 16 (-42.86%)
Mutual labels:  notification
growl-alert
A simple growl like notification system.
Stars: ✭ 14 (-50%)
Mutual labels:  notification
wxpusher-sdk-python
微信消息实时推送服务[WxPusher]的Python版本sdk,可以通过API实时给个人微信推送消息。wechat pusher.
Stars: ✭ 156 (+457.14%)
Mutual labels:  notification
react-notification-alert
React bootstrap 4 notification alert
Stars: ✭ 34 (+21.43%)
Mutual labels:  notification

Laravel Notification Settings

Laravel Laravel GitHub


laravel-notification-settings is a Laravel package that allows you to check the notification settings before send them.

💿 Installation

composer require williamcruzme/laravel-notification-settings

🏁 Getting Started

1. Adding trait

In your user model add the Notifiable trait. This trait supports custom guards:

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Millions\Notifications\Notifiable;

class User extends Authenticatable
{
    use Notifiable;
}

2. Running migrations

php artisan migrate

Sometimes you may need to customize the migrations. Using the vendor:publish command you can export the migrations:

php artisan vendor:publish --tag=migrations

3. Creating seeder

Add all notifications that require settings. Notification that are not added will be sent without verification:

php artisan make:seeder NotificationTypesTableSeeder
/**
 * Run the database seeds.
 *
 * @return void
 */
public function run()
{
    DB::table('notification_types')->insert([
        'name' => 'App\\Notifications\\Welcome',
        'display_text' => 'Welcome message',
        'status' => true,
    ]);
}

4. Adding routes

Using the Notification facade to import the routes for manage the settings:

Notification::routes();

🚀 Usage

Using The Notifiable Trait

This trait contains one method that may be used to send notifications: notify. The notify method check if the user wants to receive it, and expects to receive a notification instance:

use App\Notifications\InvoicePaid;

$user->notify(new InvoicePaid($invoice));

Using The Notification Facade

Alternatively, you may send notifications via the Notification facade. This is useful primarily when you need to send a notification to multiple notifiable entities such as a collection of users. To send notifications using the facade, pass all of the notifiable entities and the notification instance to the send method:

use Millions\Notifications\Facades\Notification;

Notification::send($users, new InvoicePaid($invoice));

🌐 Routes

Get notifications

Method URI
GET /notifications

Mark as read

Method URI
PATCH /notifications/read

Delete notification

Method URI
DELETE /notifications/{notificationId}

Get notification settings

Method URI
GET /settings/notifications

Update notification setting

Method URI
PATCH /settings/notifications/{notificationTypeId}

Body Params

{
    "status": true, // false
}

🎨 Customizing

First of all, create your own NotificationSettingController controllers and add the ManageNotificationSettings trait.

Second, modify the namespace of the Notification facade routes:

Notification::routesForSettings('App\Http\Controllers');

Custom request validations

The rules validationErrorMessages methods in the NotificationSettingController allows you override the default request validations:

<?php

namespace App\Http\Controllers;

use Millions\Notifications\ManageNotificationSettings;

class NotificationSettingController extends Controller {

    use ManageNotificationSettings;
    
    /**
     * Get the notification settings validation rules.
     *
     * @return array
     */
    protected function rules()
    {
        return [
            'status' => ['required', 'boolean'],
        ];
    }

    /**
     * Get the notification settings validation error messages.
     *
     * @return array
     */
    protected function validationErrorMessages()
    {
        return [];
    }
}

Custom response

The sendResponse method in the NotificationSettingController allows you override the default response:

<?php

namespace App\Http\Controllers;

use Millions\Notifications\ManageNotificationSettings;

class NotificationSettingController extends Controller {

    use ManageNotificationSettings;
    
    /**
     * Get the response for a successful listing notification settings.
     *
     * @param  array  $response
     * @return \Illuminate\Http\JsonResponse
     */
    protected function sendResponse($response)
    {
        return response()->json($response);
    }
}

Custom guards

The guard method in the NotificationSettingController allows you override the default guard:

<?php

namespace App\Http\Controllers;

use Millions\Notifications\ManageNotificationSettings;

class NotificationSettingController extends Controller {

    use ManageNotificationSettings;
    
    /**
     * Get the guard to be used during notifications management.
     *
     * @return \Illuminate\Contracts\Auth\StatefulGuard
     */
    protected function guard()
    {
        return auth('admin')->guard();
    }
}

🚸 Contributing

You are welcome to contribute to this project, but before you do, please make sure you read the contribution guide.

🔒 License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].