Yousef Altaf
Yousef Altaf

Reputation: 2763

Laravel 5: Use implode() with Eloquent the right way

I have a checkbox group and want to insert them in my database as val(1,2,3).

here is my blade

<div class="form-group">
     @foreach($extra as $ext)
        <div class="checkbox">
           <label>
          {{ Form::checkbox('extra_services[]', $ext->id, null, ['class' => 'checkbox']) }}
          {!! $ext->title !!}
           </label>
        </div>
     @endforeach
</div>

and here is controller

    $temp->currency = $request->currency;
    $temp->implode($request->extra_services, ',');
    $temp->save();

I got

strtolower() expects parameter 1 to be string, array given

what is the right way to insert my checkbox values into my db as (1, 2, 3)?

Upvotes: 3

Views: 35019

Answers (3)

yash chauhan
yash chauhan

Reputation: 1

$locations = implode(', ',Arr::pluck($business->locations, 'name'));

Upvotes: 0

LF-DevJourney
LF-DevJourney

Reputation: 28529

You need change

$temp->implode($request->extra_services, ',');

to

$temp->extra_services = implode(',', $request->extra_services);

Upvotes: 5

xar
xar

Reputation: 1439

I'm assuming you want to assign the value to $temp->extra_services. The code then should be

$temp->extra_services = collect($request->extra_services)->implode(',');

Upvotes: 4

Related Questions