我需要从搜索页面添加诸如topic/category?search="word"
之类的路线,但是我不知道如何添加。
现在,在我看来,我在内容上方得到一个字:
@if(isset($details))
<p> The Search results for your query <b> {{ $query }} </b> are :</p>
@endif
<form action="/topic/{{strtolower($category->category)}}/career-solutions" method="POST" role="search">
{{ csrf_field() }}
<input type="hidden" name="c" value="{{$category->id }}">
<input type="hidden" name="d" value="{{$category->category }}">
<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>
这是我的路线和我尝试过的方法:
Route::any ( '/topic/{category?}/career-solutions/{q?}/{page?}', 'CategoryController@searchCareer' );
这是我的控制人:
$q = Input::get ( 'q' );
$user = CareerSolution::where ( 'subject', 'LIKE', '%' . $q . '%' )
->where('career_solutions.topic_category_id', '=', $c)
->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();
if (count ( $user ) > 0)
return view ( 'category-search',$data )->withDetails ( $user )->withQuery ( $q )->with(compact('topic_id'))->with(compact('account'))->with(compact('category'))->with(compact('c'))->with(compact('d'));
else
return view ( 'category-search',$data )->withMessage ( 'No Details found. Try to search again !' );
现在,当我按搜索时,它会打开一个带有链接/topic/courses/career-solutions
的页面,我需要添加它... ?sesrch="word"
。
答案 0 :(得分:1)
如果使用查询参数,则http动词应为GET
接下来,网址将类似于
/?x=y&p=q
因此表单操作将
<form action="/topic/{{strtolower($category->category)}}/career-solutions?x=y&p=q" method="GET" role="search">
和您的控制器中
$x = $request->input('x');
和
$p = $request->input('q');