首页 > 解决方案 > 无需登录的搜索功能

问题描述

这是一个搜索功能,应登录以查看搜索刀片。我想在不需要学生登录的情况下显示搜索刀片并允许任何人使用此功能

这是我在控制器中的搜索功能

public function search()
{
    $q = Input::get ( 'q' );
    if($q != ""){
        $student = Student::where ( 'uniid', 'LIKE', '%' . $q . '%' )->get();
        if (count ( $student ) > 0)
            return view ( 'search' )->withDetails ( $student )->withQuery ( $q );
        else
            return view ( 'search' )->withMessage ( 'not fount' );
    }
    return view ( 'search' )->withMessage ( 'write the number want to search' );
}

这是我的搜索刀片

<!DOCTYPE html>
 <html>
  <head>
  <title>Search</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  </head>
  <body>
  <div class="container">
  <form action="/search" method="POST" role="search">
  {{ csrf_field() }}
  <div class="input-group">
    <input type="text" class="form-control" name="q"
        placeholder="search.."> <span class="input-group-btn">
        <button type="submit" class="btn btn-default">
            <span class="glyphicon glyphicon-search"></span>
        </button>
    </span>
</div>
</form>
 <div class="container">
@if(isset($details))
<table class="table table-striped">
    <thead>
        <tr>
            <th> unique id</th>
            <th>  order statuse</th>
        </tr>
    </thead>
    <tbody>
        @foreach($details as $request)
        <tr>
            <td>{{$request->uniid}}</td>
            <td>{{$request->status->name}}</td>
        </tr>
        @endforeach
    </tbody>
</table>
@elseif(isset($message))
<p>{{ $message }}</p>
@endif
</div>
</body>
</html>

标签: phplaravelsearch

解决方案


推荐阅读