확인란을 사용하여보기에서 데이터를 필터링하는 방법을 파악하는 데 어려움을 겪고 있습니다. 하나의 위치 만 선택하면 간단합니다. 하지만 여러 위치를 선택하면 어떻게 될까요? 이것은 @foreach입니까?Laravel : 여러 확인란의 입력을 기반으로 결과 필터링
내보기
<form method="post" action="filter">
{{ csrf_field() }}
<input type="checkbox" name="locationfilter[]" value="Chicago">Chicago</label>
<input type="checkbox" name="locationfilter[]" value="New York">New York</label>
<button type="submit" class="btn btn-primary"> Submit </button>
당신은 지정된 배열의 값을 얻을 수 whereIn()
기능을 사용할 수 있습니다
$lofilter = implode(", ", $request->get('locationfilter'));
$mypostings = Postings::where('location', 'LIKE', '%'. $lofilter .'%')->get();
보기 또는 컨트롤러의 위치를 필터링하려고합니까? – darthaditya
또는 조건을 필터링하여 위치를 필터링 하시겠습니까? –
'whereIN' 조건은 Laravel에서 쉼표로 구분 된 일치를 위해 작동합니다. – Webinion