I’m trying to do multiple select filter data based on the source on the ticket using a query in Laravel 8 but when I select the multiple sources the data appears only the first choice from the source I chose to filter
he is my code
my controller
public function dashboard_realtime_filter(Request $request){
$project = Auth::user()->id_project_sementara;
$currentDate = Carbon::now()->format('Y-m-d');
$source = $request->source;
$string = implode(', ',$source);
$served = DB::select(DB::raw(
"SELECT
COUNT(update_date) AS update_date
FROM ticket
WHERE DATE_PART('DAY',CURRENT_TIMESTAMP) = DATE_PART('DAY',ticket.created_at)
AND ticket.id_project = '$project'
AND ticket.source IN ('$string')
"));
$serveds = $served[0]->update_date;
return view('dashboard.dashboard_realtime', [
'served' => $serveds,
'master_skill' => Master_skill::where('skill_name', '!=', 'All')->get()
]);
}
my filter form
<form action="{{ url('../dashboard/realtime/filter') }}" method="GET">
@csrf
<div class="col-lg-12 col-md-12 d-inline justify-content-end d-flex mt-3 mb-3">
<div class="dropdown">
<select id="source" name="source[]" class="form-select show-tick ms select2"
data-placeholder="Select By Channel" multiple required>
@foreach ($master_skill as $name )
<option value='{{$name->skill_name}}'>{{$name->skill_name}}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-success">Filter</button>
</div>
</form>
2
Answers
if each
$source
is text you need to encapsulate each$source
into a string as'$source'
:Please try replacing
$string = implode(', ',$source);
with
$string = implode(',',$source);
Extra blank space might be causing the problem.