I want to make a filter by supervisors, but when passing the name, it is passed through the underscore _ . Ok, I have replaced this when verify has() in $request. Example of the passing name into request
I'm not sure if this is the right way, but it works.
My Controller:
public function index(Request $request) {
$supervisors = User::where('role','supervisor')->get();
$filteredSupervisors = null;
foreach ($supervisors as $supervisor) {
if ($request->has(str_replace(" ","_",$supervisor->name)))
$filteredSupervisors[] = $supervisor->id;
}
if ($filteredSupervisors != null)
$projectsQuery->whereIn('user_id', $filteredSupervisors);
$projects = $projectsQuery->paginate(4);
My View:
@foreach($supervisors as $supervisor)
<label>{{ preg_replace('~^(\S++)\s++(\S)\S++\s++(\S)\S++$~u', '$1 $2.$3.', $supervisor->name) }}
<input name='{{ $supervisor->name }}' type='checkbox'>
</label>
@endforeach