php - 如何添加到我的搜索链接?search="word"?
问题描述
我需要从类似的搜索页面添加到我的路线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"
...。
解决方案
如果您使用查询参数,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');
推荐阅读
- javascript - 使用 eq 与不使用 eq 有什么区别?
- go - 如何将接口输入参数重置为 nil 并且调用者可以进行 nil 检查?
- vector - 用置换检验和余弦相似度比较两组向量
- javascript - 即使使用 await,Firebase 函数也不会等待异步代码
- java - 使数组相等的最小计数
- sql - 需要在 SQL 中计算最终日期
- python - 为什么在这个 8 皇后算法中需要“list()”?
- python - 基础镜像满足 tensorflow 版本但 docker 仍然从 requirements.txt 下载 tensorflow
- php - 如何基于函数内的foreach循环在php中编写if条件?
- php - API 平台:规范化和非规范化继承映射的 Doctrine 实体