на самом деле вам не нужно json_encode вручную, laravel имеет возможность cast любой атрибут для массива / json:
Мы предполагаем, что ваша модель называется Item
.
//Model
class Item{
protected $casts = [
'industry' => 'array'
]
//snap
}
//Controller
class ItemController extends Controller{
//snap
public function update($id,\Request $request){
$item = Item::findOrFail($item);
// no need to json_encode! laravel handle this magically!
$item->industry = $request->industry;
$item->save();
}
//snap
public function show($id){
$item = Item::findOrFail($id);
return view('item.show',compact('item'));
}
}
@php
// just making an array of industry options, so later we will iterate on it.
$industries = [
'Agriculture & Food Processing',
'Automobiles',
'Banking & Financial Services',
//list all the industries here
];
@endphp
<select id="industry" name="industry[]" class="form-control" multiple>
<!-- default value -->
<option value="">Select Option </option>
@foreach($industries as $industry)
<!-- if industry found in current item's industry field we add selected to it -->
<option @if(in_array($industry,$item->industry)) selected @endif>{{$industry}}</option>
@endforeach
</select>