Merhaba,
<div class="filter-checklist">
<h5>İlçe</h5>
<div class="checklist-items feature-checklist hideContent" style="height: 300px; overflow-y: scroll !important;">
@foreach($towns as $town)
<div class="custom-control custom-checkbox checkbox-outline checkbox-outline-primary">
<input type="checkbox" class="custom-control-input" name="town[]" value="{{ $town->id }}" id="{{ $town->id }}">
<label class="custom-control-label" for="{{ $town->id }}">{{ $town->name }}</label>
</div>
@endforeach
</div>
</div>
şöyle bir kod parçacığı var. Formu post ettikten sonra seçilenleri "checked" ile işaretlemek istiyorum. Şöyle bir şey
denedim fakat işe yaramadı.
@if(is_array(old('town')) && in_array($town->id, old('town'))) checked @endif
Controller Kısmı şu şekilde;
public function searchFilter(Request $request)
{
$cityId = $request->input('city_id');
$towns = Town::where('city_id', $cityId)->get();
$selectedTowns = Town::whereIn('id', $request->input('town'))->get();
$townIds = array();
foreach ($selectedTowns as $town) {
array_push($townIds, $town->id);
}
$places = Place::whereIn('town_id', $townIds)->where('city_id', $cityId)->get();
return view('places.search', compact('places', 'cityId', 'towns'));
}