From 9f7f4eb35aef784483c97efc9e66ba605be7b4ee Mon Sep 17 00:00:00 2001 From: Abdulrahman elzahaby Date: Thu, 11 Feb 2021 01:57:19 +0200 Subject: [PATCH] handle error if base_string value is null TypeError Argument 1 passed to Illuminate\Support\Str::Tanmuhittin\LaravelGoogleTranslate\{closure}() must be of the type string, null given, called in /home/anskal/Work/web/vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php on line 88 https://flareapp.io/share/bP9QaJOP --- src/Controller.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Controller.php b/src/Controller.php index 31ab43c0..31def037 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -184,17 +184,19 @@ public function postTranslateMissing(Request $request){ // Translation already exists. Skip continue; } - $translated_text = Str::apiTranslateWithAttributes($base_string->value, $newLocale, $base_locale); - request()->replace([ - 'value' => $translated_text, - 'name' => $newLocale . '|' . $base_string->key, - ]); - app()->call( - 'Barryvdh\TranslationManager\Controller@postEdit', - [ - 'group' => $group - ] - ); + if(!empty($base_string->value)) { + $translated_text = Str::apiTranslateWithAttributes($base_string->value, $newLocale, $base_locale); + request()->replace([ + 'value' => $translated_text, + 'name' => $newLocale . '|' . $base_string->key, + ]); + app()->call( + 'Barryvdh\TranslationManager\Controller@postEdit', + [ + 'group' => $group + ] + ); + } } return redirect()->back(); }