dongqiang8683 2015-08-05 01:43
浏览 63

单击时如何获取链接的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

  • 写回答

2条回答 默认 最新

  • doudun5009 2015-08-05 02:48
    关注

    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);
     }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?