简体   繁体   中英

How to add to my search link ?search=“word”?

I need to add to my route from search page something like topic/category?search="word" , but I don't know how to add it.

Now, in my view I get the word above my content:

 @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>

Here is my route and what I tried:

Route::any ( '/topic/{category?}/career-solutions/{q?}/{page?}', 'CategoryController@searchCareer' );

Here is my controller:

$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 !' );


Now, when I press search, it opens a page with link /topic/courses/career-solutions , I need to add to it... ?sesrch="word" .

If you are using query paramter, the http verb should be GET,

Next the url will be something like

/?x=y&p=q

so the form action will be

<form action="/topic/{{strtolower($category->category)}}/career-solutions?x=y&p=q" method="GET" role="search">

and in your controller

$x = $request->input('x');

and

$p = $request->input('q');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM