标签系统-单击标签即可按标签搜索

我想通过标签进行搜索。单击标签时,向我显示所有具有标签值的内容(例如model,tag1,tag2等)。为此,我制作了一个页面并测试了该页面是否可以显示我需要的内容。通过->where('tag','=','model'),我得到了所有带有`tag = model'的帖子。但是现在,我需要根据单击的标签进行显示。 因此,这是我的单篇新闻:

标签系统-单击标签即可按标签搜索

这些代码是通过以下代码生成的:

<div class="container">
            <label>Tags

              <a href="{{ url('') }}">
                  <input class="input-tags" type="text" data-role="tagsinput" value="{{ $news->tag }}" disabled>
              </a>


              </label>
            </div>

        </div>

此刻是我的控制人:

public function newsTag()
        {

                $data = $this->data;



                $data['news_details'] = News::with('category_name')->where('locale',Session::get('locale'))->where('tag','model')->orderBy('created_at','desc')->get();


                $data['categories'] = Category::with(['news' => function ($q){
                        $q->orderBy('title','asc');}])->where('category','news')->where('locale',Session::get('locale'))->get();

                // $data['categories'] = Category::with('news')->where('category',Session::get('locale'))->get();

                $data['instanews_details'] = InstagramNews::where('locale',Session::get('locale'))->where('category','news')->get();

                // $displayitem = DisplayItem::where('slug',url('project'))->first();

                // $data['page'] = $displayitem;
                // date_default_timezone_set('Asia/Kolkata');
                // // return $date = date('Y-m-d H:i:s');
                // return $date = strtotime('-1 hour');
                // echo 'John visited last ' . $date;

                $data['title'] = trans('fab.news');;

                $data['breadcrumb'] = 'news';

                // $data['menu'] = $tag->title;

                $data['metadescription'] = "news";

                $data['metatitle'] = 'news';

                // $data['blogs'] = $tag->blog;

                return view('news.news_tag',$data);

        }

这是我的路线:

Route::get('news_tag','ModelController@newsTag');

这是我的搜索结果页面-news_tag.blade.php:

@extends('layout.front.template')
@section('content')

<!-- Profile talent section -->
   <section class="vc_row wpb_row vc_row-fluid modificartion" style="overflow: hidden;">
   <div class="container news-container">
      <div id="news-rows" class="row">
          <div class="wpb_column vc_column_container vc_col-sm-12">
              <div class="vc_column-inner ">
                  <div class="wpb_wrapper">
                     <section class="gallery-element isotop padding-item none-padding hidden-s hidden-sm hidden-xs">
                        <div class="container">
                           <div class="header-element">
                               <h3 id="newstxt" class="title-element font-disolve">@lang('fab.news')</h3>
                           </div>
                           <div class="content-tab">
                               <div id="options" class="clearfix">
                                  <a href="javascript:void(0)">
                                   <ul id="filters" class="option-set clearfix inline-mainb" data-option-key="filter" data-toggle="modal" data-target="#myModal">
                                      @lang('fab.newsletter')
                                   </ul>
                                 </a>
                               </div>

                               <div class="row" style="margin-right:0px;bottom: 40px; position: relative">

                                 <div class="col-md-3 contentWrap" id="column1" style="padding-right: 0px;">
                                   <ul class="scroller3 content">
                                     @foreach($news_details as $key => $news)
                                         <!-- <ul class="scroller1"> -->


                                             <a href="{{ url('news') }}/{{ $news->slug }}">
                                               <div class="element transition {{ $news->category_name->slug }} editorial news video-exhibition" style="width: 100%">
                                                 <div class="item-gallery {{ $news->news_class }}">
                                                   <div class="content-item">
                                                       <img src="{{ url('images/news') }}/{{ $news->image }}"/>
                                                      <div class="text">
                                                          <div class="name">{{ $news->category_name->title }}</div>
                                                          <div class="content-gallery-grid">
                                                             <h3 class="title">
                                                               <!-- <a href="{{ url('news') }}/{{ $news->slug }}"> -->
                                                                 {{ $news->title }}
                                                               <!-- </a> -->
                                                             </h3>
                                                          </div>
                                                      </div>
                                                   </div>
                                                 </div>
                                              </div>
                                             </a>


                                     @endforeach
                                   </ul>
                                 </div><!-- 1st col -->
                               </div>

@stop

因此,总而言之,我需要基于每个新闻的单个新闻的标签来创建此搜索功能。 因此,如果ID为1的新闻有tags - test,tag,me,phone,并且我按了tag,我想重定向到news_tag页面,并且只获得{{1}列中带有tag的帖子} tag中的}。

标签系统-单击标签即可按标签搜索

mxmkeai 回答:标签系统-单击标签即可按标签搜索

感谢您发布问题!

是否可以更改代码的结构,使其支持“新闻与标签”之间的多对多关系?

从我在您的应用中看到的消息来看,新闻可以有很多标签,而标签可以有很多新闻项目。

以下是我经常从Spatie的开发人员处进行标记的软件包:

https://github.com/spatie/laravel-tags

该链接上的示例显示了如何向新闻项目(或应用程序中的其他表格)添加标签。

这对您要达到的目标有帮助吗?

本文链接:https://www.f2er.com/3167574.html

大家都在问