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
- 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"),
];
}
}
$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" => "تفاصيل الفاتورة" ]