Browse Source

add sms make notif func to helper and some change

mahdi
mahdihty 4 years ago
parent
commit
90b1c635ef
  1. 10
      app/Models/User.php
  2. 4
      app/Providers/AppServiceProvider.php
  3. 11
      app/Utilities/HelperClass/NotificationHelper.php
  4. 12
      resources/lang/fa/notification.php
  5. 4
      routes/api.php

10
app/Models/User.php

@ -60,6 +60,16 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
return request('_business_info')['id'] ?? null; return request('_business_info')['id'] ?? null;
} }
/**
* Specifies the user's phone number
*
* @return string
*/
public function routeNotificationForSms()
{
return $this->mobile;
}
public function updateRelations() public function updateRelations()
{ {
// projects relations // projects relations

4
app/Providers/AppServiceProvider.php

@ -4,6 +4,7 @@ namespace App\Providers;
use App\Channels\DBChannel; use App\Channels\DBChannel;
use App\Channels\FcmChannel; use App\Channels\FcmChannel;
use App\Channels\SmsChannel;
use App\Channels\SocketChannel; use App\Channels\SocketChannel;
use Illuminate\Notifications\ChannelManager; use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
@ -29,6 +30,9 @@ class AppServiceProvider extends ServiceProvider
$service->extend('db', function ($app) { $service->extend('db', function ($app) {
return new DBChannel(); return new DBChannel();
}); });
$service->extend('sms', function ($app) {
return new SmsChannel(new HttpClient, config('smsirlaravel.webservice-url'));
});
}); });
} }

11
app/Utilities/HelperClass/NotificationHelper.php

@ -8,11 +8,14 @@ use App\Notifications\DBNotification;
use App\Notifications\FcmNotification; use App\Notifications\FcmNotification;
use App\Notifications\MailNotification; use App\Notifications\MailNotification;
use App\Notifications\SocketNotification; use App\Notifications\SocketNotification;
use App\Notifications\SmsNotification;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
class NotificationHelper class NotificationHelper
{ {
protected $notif; protected $notif;
protected $sms_notif;
/** /**
* Make notification object * Make notification object
* *
@ -33,6 +36,12 @@ class NotificationHelper
return $this; return $this;
} }
public function makeSmsNotif($template_name, $options = [])
{
$this->sms_notif = __('notification.sms.templates.'.$template_name, $options);
return $this;
}
/** /**
* Fetch message from notifications lang file * Fetch message from notifications lang file
* *
@ -56,7 +65,7 @@ class NotificationHelper
public function sendNotifications($users, $level = null) { public function sendNotifications($users, $level = null) {
switch ($level) { switch ($level) {
case "emergency": case "emergency":
// Notification::send($users, new SmsNotification($notif));
Notification::send($users, new SmsNotification($this->sms_notif, 'ultraFastSend'));
case "critical": case "critical":
Notification::send($users, new MailNotification($this->notif)); Notification::send($users, new MailNotification($this->notif));
case "high": case "high":

12
resources/lang/fa/notification.php

@ -85,4 +85,16 @@ return [
'suspended' => 'حساب مسدود شد.', 'suspended' => 'حساب مسدود شد.',
], ],
'sms' => [
'templates' => [
'template_name' => [
'template_id' => 'asdasd',
'params' => [
'user' => ':user',
'business' => ':business',
]
]
]
]
]; ];

4
routes/api.php

@ -8,7 +8,9 @@ $router->get('/lab', function () {
$router->get('/ntest', function () { $router->get('/ntest', function () {
$user = \App\Models\User::find(1); $user = \App\Models\User::find(1);
\Illuminate\Support\Facades\Notification::send($user, new \App\Notifications\SocketNotification(['title' => "hello!!!", 'body' => 'sss']));
\Illuminate\Support\Facades\Notification::send($user, new \App\Notifications\SmsNotification(['verification_code' => "1234"]));
(new \App\Utilities\HelperClass\NotificationHelper())
->makeSmsNotif('template_name', ['user' => 'myUser', 'business' => 'myBusiness']);
})->middleware('bindBusiness'); })->middleware('bindBusiness');
$router->group(['prefix' => 'actions'], function () use ($router) { $router->group(['prefix' => 'actions'], function () use ($router) {
$router->group(['prefix' => 'businesses'], function () use ($router) { $router->group(['prefix' => 'businesses'], function () use ($router) {

Loading…
Cancel
Save