I am using laravel 5.5 I have a multi-select dropdown. if I don't select any value it generates an error. "implode(): Invalid arguments passed"
<select multiple="multiple" name="language[]">
@foreach($language_data as $language)
<option value="{{$language->language_id}}">{{$language->language_name}}</option>
@endforeach
</select>
Controller
$language = $request->input('language');
$language = implode(',', $language);
DB::table('language')->insert(['language' => $language,]);
just use a simple if:
if($request->input('language') !== ''){
$language = $request->input('language');
$language = implode(',', $language);
DB::table('language')->insert(['language' => $language,]);
}
And you can have a fall back if needed to define a language in the backend if none is selected like below
$request->input('language') !== '' ? $language = $request->input('language') : $language = 'en_GB';
$language = implode(',', $language);
DB::table('language')->insert(['language' => $language,]);