saben xq al hacer la llamada en el Search (Sin datos) y haber seleccionado FREELANCER, me devuelve una lista de usuario completa osea todos los usuarios de todos los roles y tipo. cuandlo solo quiero listar los Freelancer?
Codigo del form search:
<form action="{{ route('search') }}" method="GET" class="flex-grow-1">
<div class="input-group">
<a class="text-reset bg-soft-secondary fs-12 rounded-left d-lg-none p-2" href="javascript:void(0);" data-toggle="class-toggle" data-target=".front-header-search">
<i class="las la-arrow-left la-2x"></i>
</a>
<div class="input-group-prepend flex-grow-1 d-none d-sm-block">
<input type="text" class="form-control" placeholder="I'm looking for" name="keyword">
</div>
<select class="form-control aiz-selectpicker" name="type">
<option value="freelancer" @isset($type)
@if ($type = 'freelancer')
selected
@endif
@endisset>{{ translate('Freelancers') }}</option>
<option value="project" @isset($type)
@if ($type == 'project')
selected
@endif
@endisset>{{ translate('Projects') }}</option>
<option value="service" @isset($type)
@if ($type == 'service')
selected
@endif
@endisset>{{ translate('Services') }}</option>
</select>
<div class="input-group-append">
<button type="submit" class="btn btn-icon btn-primary">
<i class="las la-search la-rotate-270"></i>
</button>
</div>
</div>
</form>
y este es el controlador del Search:
public function index(Request $request){
if($request->type == 'freelancer'){
$type = 'freelancer';
$keyword = $request->keyword;
$rating = $request->rating;
$freelancers = UserProfile::query();
if($request->keyword != null){
$user_ids = User::where('user_type', 'freelancer')->where('name', 'like', '%'.$keyword.'%')->pluck('id');
$freelancers = $freelancers->whereIn('user_id', $user_ids);
}
if($request->rating != null){
if ($rating == "4+") {
$freelancers = $freelancers->where('rating', '>', 4);
}
else {
$freelancers = $freelancers->whereIn('rating', explode('-', $rating));
}
}
$total = count($freelancers->get());
$freelancers = $freelancers->paginate(8)->appends($request->query());
return view('frontend.default.freelancers-listing', compact('freelancers', 'total', 'keyword', 'type', 'rating'));
} else if($request->type == 'service'){
$type = 'service';
$keyword = $request->keyword;
$rating = $request->rating;
$services = Service::where('id', '!=', null);
if($request->keyword != null){
$service_ids = Service::where('title', 'like', '%'.$keyword.'%')->pluck('id');
$services = $services->whereIn('id', $service_ids);
}
$total = count($services->get());
$services = $services->paginate(8)->appends($request->query());
return view('frontend.default.services-listing', compact('services', 'total', 'keyword', 'type', 'rating'));
}
else {
$type = 'project';
$keyword = $request->keyword;
$projectType = array('Fixed', 'Long Term');
$bids = $request->bids;
$sort = $request->sort;
$category_id = (ProjectCategory::where('slug', $request->category)->first() != null) ? ProjectCategory::where('slug', $request->category)->first()->id : null;
$category_ids = CategoryUtility::children_ids($category_id);
$category_ids[] = $category_id;
$project_approval = SystemConfiguration::where('type','project_approval')->first()->value;
if($project_approval == 1){
$projects = Project::biddable()->notcancel()->open()->where('private', '0')->where('project_approval',1);
}else{
$projects = Project::biddable()->notcancel()->open()->where('private', '0');
}
if($category_id != null){
$projects = $projects->whereIn('project_category_id', $category_ids);
}
$projects = $projects->where('name', 'like', '%'.$keyword.'%');
if($request->projectType != null){
$projectType = $request->projectType;
$projects = $projects->whereIn('type', $projectType);
}
if($request->bids != null){
if ($bids == "30+") {
$projects = $projects->where('bids', '>', 30);
}
else {
$projects = $projects->whereIn('bids', explode('-', $bids));
}
}
switch ($sort) {
case '1':
$projects = $projects->orderBy('created_at', 'desc');
break;
case '2':
$projects = $projects->orderBy('price', 'asc');
break;
case '3':
$projects = $projects->orderBy('price', 'desc');
break;
case '4':
$projects = $projects->orderBy('bids', 'asc');
break;
case '5':
$projects = $projects->orderBy('bids', 'desc');
break;
default:
$projects = $projects->latest();
break;
}
$total = count($projects->get());
$projects = $projects->paginate(8)->appends($request->query());
return view('frontend.default.projects-listing', compact('projects', 'keyword', 'total', 'type', 'projectType', 'bids', 'sort', 'category_id'));
}
}
public function searchBySkill(Request $request, $id, $type){
$skill = Skill::findOrFail($id);
$keyword = $request->keyword;
$projectType = array('Fixed', 'Long Term');
$bids = $request->bids;
$sort = $request->sort;
if($type == 'projects'){
$project_approval = SystemConfiguration::where('type','project_approval')->first()->value;
if($project_approval == 1){
$projects = Project::biddable()->notcancel()->open()->where('private', '0')->where('project_approval',1);
}else{
$projects = Project::biddable()->notcancel()->open()->where('private', '0');
}
$projects = $projects->where('skills', 'like', '%'.'"'.$id.'"'.'%')->latest();
$total = count($projects->get());
$projects = $projects->paginate(8)->appends($request->query());
return view('frontend.default.projects-listing', compact('projects', 'keyword', 'total', 'type', 'projectType', 'bids', 'sort'));
}
}
donde esta el error ?
mi tabla es: user y dentro de ella esta: id provider_id user_type name
Dentro de ''user_type'' tengo los 2 tipo de usuarios : freelance y client.
pero aun así me lista todos los usuarios y solo quiero que llame a los freelance, en la vista tengo:
@foreach ($freelancers as $key => $freelancer)
<h5 class="fw-600 mb-1">{{ $freelancer->user->user_type }}</h5>
@endforeach
que puedo hacer para solo listar los usuarios freelance??
where('user_type', 'freelancer')
solo se esta aplicando cuando$request->keyword != null
en lugar de siempre que es$request->type == 'freelancer'
, si no entiendo mal lo que quieres hacer este where deberia esta fuera del condicionalif($request->keyword != null)