From 6de9a528cc1f25003f91833745496d542a57e73f Mon Sep 17 00:00:00 2001 From: mahdihty Date: Tue, 9 Mar 2021 10:56:15 +0330 Subject: [PATCH] clean code in BusinessUserCreateNotif.php --- app/Listeners/BusinessUserCreateNotif.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/Listeners/BusinessUserCreateNotif.php b/app/Listeners/BusinessUserCreateNotif.php index 41a3ab5..a7b06d0 100644 --- a/app/Listeners/BusinessUserCreateNotif.php +++ b/app/Listeners/BusinessUserCreateNotif.php @@ -38,10 +38,10 @@ class BusinessUserCreateNotif $owners = Business::findOrFail($payload->business)->owners()->where('id', '!=', $new_user->id)->get(); $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); @@ -49,4 +49,18 @@ class BusinessUserCreateNotif Notification::send($users, new DBNotification($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); + } }