单击时如何获取链接的http请求

Iam making a tag system,when user click a certain link ,display all results related to it

In view i have a link like this

@foreach($productTags as $tags)
    <a href="{{ action('Product\ProductController@searchTags', ['tags_id' => $tags->id]) }}" id="tags">{{$tags->tags}}</a>
@endforeach

Routes

Route::get('tags/{tags}','Product\ProductController@searchTags');

I want to get it in controller which is like this

public function searchTags($tags)
       {
        dd($request->get('tags_ids'));
         $search = \DB::table('products')->select('tags','id')
                               ->where('tags',$tags)->get();
                               return view('products.show.search',
                                                            compact('search'));
       }

But iam getting null

I'm unsure about what you are trying to accomplish. When you click a tag should you see products that have that tag?

There are a couple things going on here, I'll point out.

You're mixing GET and POST. searchTags(Request $request) accepts a Request as if a form was being submitted to it. However the route is a GET and the link in your view will produce a GET request.

Assuming that you want to click a tag and see products that also have that tag, you might try something like the following:

products/show.blade.php:

@foreach($productTags as $tag)
  <a href="/tags/{{ $tag->id }}">{{ $tag->name }}</a>
@endforeach

routes.php:

Route::get('tags/{id}', 'TagsControlller@show');

TagsController.php:

/**
 * Display products with tag 
 *
 * @param $id
 * @return Response
 */
 public function show($id)
 {
     $products = Product::with('tags')->where(['id' => $id])->get();
     return view('tags.show')->with('products', $products);
 }

in your ProductController

public function searchTags($tag_id) 
{
         $search = \DB::table('products')->select('tags','id')
              ->where('tag_id','=', $tag_id)->get();
         return view('products.show.search',
              compact('search'));

}