digitalcloud / multilingual-notification
This package is abandoned and no longer maintained.
The author suggests using the https://github.com/DigitalCloud/reactive-notification package instead.
Reactive Laravel Notification
v1.0
2018-12-30 13:10 UTC
Requires
- php: >=7.1.0
This package is auto-updated.
Last update: 2022-02-01 13:14:53 UTC
README
Installation
PHP >=5.6 and Laravel ^5.3 are required.
To get the latest version of Reactive Laravel notification, simply require the project using Composer:
composer require digitalcloud/reactive-notification
publishing migration file
php artisan vendor:publish --provider="Digitalcloud\ReactiveNotification\ReactiveNotificationServiceProvider"
migrate published migration files
php artisan migrate
Usage
- Change trait used in model from
Illuminate\Notifications\Notifiable
toDigitalcloud\ReactiveNotification\Traits\Notifiable
<?php namespace App; use Digitalcloud\ReactiveNotification\Traits\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable; }
- Change delivery channel from
database
orDatabaseChannel
toDigitalcloud\ReactiveNotification\Channels\DatabaseChannel
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; use Digitalcloud\ReactiveNotification\Channels\DatabaseChannel; class InvoicePaid extends Notification implements ShouldQueue { use Queueable; public function via($notifiable) { return [DatabaseChannel::class,'.../']; } public function toDatabase($notifiable){ return [ "title"=> trans("invoice_title"), "details"=> trans("invoice_details"), ]; } }
Example
$user->notify(new InvoicePaid($invoice)); \App::setLocale("en"); $result = $user->notifications()->first()->data;
the result will be
[ "title" => "Invoice title", "details" => "Invoice details" ]
then change the old language from en
into ar
\App::setLocale("ar"); $result = $user->notifications()->first()->data;
and the result will be
[ "title" => "عنوان الفاتورة", "details" => "تفاصيل الفاتورة" ]