控制器

<?php

namespace App\Http\Controllers\Home;
use Illuminate\Support\Facades\DB;
use App\Http\Model\Articles;
use Illuminate\Support\Facades\Input;
use App\Http\Controllers\Controller;

class SearchController extends Controller

{

    public function index()
    {

        $input = Input::except('_token');


        $keywords=$input['keywords'];

        $hunt = DB::table('articles')->where('title','like','%'.$keywords.'%')->get();

        $count = count($hunt);


        return view('home/search/index',compact('keywords','hunt','count'));
    }




}

 

视图

<div class="alert alert-success" role="alert"> 下面是搜索"<a style="color:red;font-weight:800;">{{$keywords}}</a>"出现的文章,共{{$count}}条 </div>
<div class="col-sm-8 blog-main">

    @foreach ($hunt as $vv)
        <div class="blog-post">
            <h2 class="blog-post-title"><a href="/posts/58" >{{$vv->title}}</a></h2>
            <p class="blog-post-meta">{{date('Y-m-d',$vv->time)}} by <a href="#">{{$vv->author}}</a></p>
            <p>{{$vv->art_content}}</p>
        </div>
    @endforeach
</div>

路由

//搜索

Route::any('/search', "\App\Http\Controllers\Home\[email protected]");

前台显示效果

laravel5 前台搜索功能的实现

 

 

 

 

相关文章:

  • 2021-11-01
  • 2021-09-08
  • 2021-11-23
  • 2021-12-03
  • 2021-10-09
  • 2021-10-09
  • 2018-02-01
  • 2021-11-03
猜你喜欢
  • 2021-11-21
  • 2021-09-25
  • 2021-11-03
  • 2021-11-18
  • 2021-11-21
  • 2021-06-11
  • 2021-12-19
相关资源
相似解决方案