Browse Source

clean code in BusinessUserCreateNotif.php

pull/1/head
mahdihty 4 years ago
parent
commit
6de9a528cc
  1. 22
      app/Listeners/BusinessUserCreateNotif.php

22
app/Listeners/BusinessUserCreateNotif.php

@ -38,10 +38,10 @@ class BusinessUserCreateNotif
$owners = Business::findOrFail($payload->business)->owners()->where('id', '!=', $new_user->id)->get(); $owners = Business::findOrFail($payload->business)->owners()->where('id', '!=', $new_user->id)->get();
$notif = [ $notif = [
'greeting' => __('notification.'.$payload->data->table_name.'.'.enum('cruds.inverse.'.$payload->data->crud_id.'.singular_name').'.greeting'),
'subject' => __('notification.'.$payload->data->table_name.'.'.enum('cruds.inverse.'.$payload->data->crud_id.'.singular_name').'.subject'),
'title' => __('notification.'.$payload->data->table_name.'.'.enum('cruds.inverse.'.$payload->data->crud_id.'.singular_name').'.title'),
'body' => __('notification.'.$payload->data->table_name.'.'.enum('cruds.inverse.'.$payload->data->crud_id.'.singular_name').'.body', ['business' => request('_business_info')['name'], 'user' => $new_user->name])
'greeting' => $this->getMessageLine($payload, 'greeting'),
'subject' => $this->getMessageLine($payload, 'subject'),
'title' => $this->getMessageLine($payload, 'title'),
'body' => $this->getMessageLine($payload, 'body', ['business' => request('_business_info')['name'], 'user' => $new_user->name])
]; ];
$users = $owners->prepend($new_user); $users = $owners->prepend($new_user);
@ -49,4 +49,18 @@ class BusinessUserCreateNotif
Notification::send($users, new DBNotification($notif)); Notification::send($users, new DBNotification($notif));
Notification::send($users, new FcmNotification($notif)); Notification::send($users, new FcmNotification($notif));
} }
/**
* Fetch message from notifications lang file
*
* @param $payload
* @param $key
* @param null $options
* @return array|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Translation\Translator|string|null
*
*/
public function getMessageLine($payload, $key, $options = null)
{
return __('notification.'.$payload->data->table_name.'.'.enum('cruds.inverse.'.$payload->data->crud_id.'.singular_name').'.'.$key, $options);
}
} }
Loading…
Cancel
Save