Мне нужно добавить условие where в мою функцию поиска, но я не знаю, как добавить это в мои окончательные результаты. Теперь, для примера: теперь мой поиск ищет имя в таблице career_solutions
, но ищет во всей таблице, и мне нужно искать только по категории 2, например. Итак, окончательный результат должен быть ... Поиск example
в категории 2
(что такое курсы).
Вот моя форма:
<form action="/topic/{{strtolower($category->category)}}/career-solutions" method="POST" role="search">
{{ csrf_field() }}
<div class="input-group">
<input type="text" class="form-control" name="q"
placeholder="Search content"> <span class="input-group-btn">
<button type="submit" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</form>
{{ $category->category }} returns me the category name, not the ID of that.
Вот мой контроллер:
public function searchCareer
{
$q = Input::get ( 'q' );
$user = CareerSolution::where ( 'subject', 'LIKE', '%' . $q . '%' )
->join('role_users' , 'role_users.user_id', '=', 'career_solutions.user_id')
->join('roles' , 'roles.id', '=', 'role_users.role_id')
->join('users', 'users.id', '=', 'career_solutions.user_id')
->join('categories', 'categories.id', '=', 'career_solutions.topic_category_id')
->orWhere ( 'career_solutions.user_id', 'LIKE', '%' . $q . '%' )
->orWhere ( 'career_solutions.id', '=', 'events.subject')
->orWhere('career_solutions.topic_category_id' ,'=', $category->id)
->orWhere ( 'career_solutions.user_id', '=', 'users.username')
->select('career_solutions.id as id','subject','users.id as user_id','username', 'profile_picture', 'role_id', 'optional', 'topic_category_id','categories.category')
->get ();
$data['test'] = 'view-career-solutions';
$data['link'] = 'search-career-solutions';
$data['type'] = 'Career Solution';
$data['typee'] = 'briefcase fa-';
$topic_id = CareerSolution::select('id', 'subject')
->get();
if (count ( $user ) > 0)
return view ( 'category-search',$data )->withDetails ( $user )->withQuery ( $q )->with(compact('topic_id'))->with(compact('account'));
else
return view ( 'category-search',$data )->withMessage ( 'No Details found. Try to search again !' );
}