Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在laravel中,如何过滤像搜索数据这样的数据?_Laravel_Search_Filter - Fatal编程技术网

在laravel中,如何过滤像搜索数据这样的数据?

在laravel中,如何过滤像搜索数据这样的数据?,laravel,search,filter,Laravel,Search,Filter,我是laravel的新手我正在做一个题库项目我如何使用下拉选择框对表格进行多重筛选搜索? 如按产品价格、产品规格和产品公司过滤并搜索数据 请帮帮我 提前谢谢 这个观景台 <div class="container"> <div align="right"> <form method="post" action="{{ url('topic/auto-search') }}"> <div class="" align

我是laravel的新手我正在做一个题库项目我如何使用下拉选择框对表格进行多重筛选搜索? 如按产品价格、产品规格和产品公司过滤并搜索数据 请帮帮我 提前谢谢

这个观景台

<div class="container">
    <div align="right">

     <form  method="post" action="{{ url('topic/auto-search') }}">
        <div class="" align="left">
            <select class="col-md-3" id='sel_topic' name='sel_topic'>
       <option value='0'>-- Select Topic --</option>
       @foreach($topics as $topic)
         <option value='{{ $topic->id }}'>{{ $topic->topic_name }}</option>
       @endforeach
   </select><span>
       <select class=" col-md-3" id='sel_stand' name='sel_stand'>
       <option value='0'>-- Select Standard --</option>
       @foreach($topics as $topic)
         <option value='{{ $topic->id }}'>{{ $topic->standard_name }}</option>
       @endforeach
   </select>
     <select class="col-md-3" id='sel_sub' name='sel_sub'>
       <option value='0'>-- Select Subject --</option>
       @foreach($topics as $topic)
         <option value='{{ $topic->id }}'>{{ $topic->subject_name }}</option>
       @endforeach
   </select>
    </span>
        {{csrf_field()}}

             <input type="text"  name="search"  id="search">
            <button type="submit" class="btn btn-outline-secondary" name="searchbutton"><i class="fa fa-search"></i></button>&nbsp;&nbsp;


    <a class="btn btn-small btn-primary pull-right" style="margin-top: 5px;" href="{{ URL::to('topic/create') }}"><i class="fa fa-plus"></i>&nbsp;ADD</a>
</div>
</form>
</div>
<div class="">
    <br><br>
<table class="table table-striped table-bordered">
    <thead>
        <tr>
            <td>ID</td>
            <td>Topic Name</td>
            <td>Standard</td>
            <td>Subject</td>
            <td>Actions</td>
        </tr>
    </thead>
    <tbody>

--选择主题--
@foreach($topics作为$topic)
{{$topic->topic_name}
@endforeach
--选择标准--
@foreach($topics作为$topic)
{{$topic->standard_name}
@endforeach
--选择主题--
@foreach($topics作为$topic)
{{$topic->subject_name}
@endforeach
{{csrf_field()}}


身份证件 主题名称 标准 主题 行动
还有我的控制器

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests\TopicRequest;
use App\Topic;
use App\Standard;
use App\Subject;
use DB;
use App\Http\Requests;
use Illuminate\Support\Facades\Input;
use App\Http\Controllers\Controller;

class TopicController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
         $topics = Topic::leftJoin('standards','topics.standard_id', '=', 'standards.id')->
                  leftJoin('subjects','topics.subject_id', '=', 'subjects.id')
        ->select('topics.*' ,'standards.standard_name','subjects.subject_name')
        ->orderBy('id', 'ASC')
        ->paginate(10);
        return view('topic.index', compact('topics'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $standards = Standard::select('id','standard_name')->paginate(10);
        $subjects = Subject::select('id','subject_name')->paginate(10);
        return view('topic.create', compact('standards','subjects'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request, [
            'name'    =>  'required',
            'standard_id' => 'required',
            'subject_id' => 'required',
        ]);
        $topic = new Topic([
            'topic_name'    =>  $request->get('name'),
            'standard_id'    =>  $request->get('standard_id'),
            'subject_id'    =>  $request->get('subject_id'),
        ]);
        $topic->save();
        return redirect()->route('topic.index')->with('success', 'Data Added');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $topic = Topic::find($id);
        $standards = Standard::select('id','standard_name')->paginate(10);
        $subjects = Subject::select('id','subject_name')->paginate(10);
        return view('topic.edit', compact('topic', 'id','standards','subjects'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $topic = Topic::find($id);
        $topic->topic_name = $request->get('name');
        $topic->standard_id = $request->get('standard_id');
        $topic->subject_id = $request->get('subject_id');
        $topic->save();
        return redirect()->route('topic.index')->with('success', 'Data Updated');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $topic = Topic::find($id);
        $topic->delete();
        return redirect()->route('topic.index')->with('success', 'Data Deleted');
    }
}

你的观点

<div class="container">
    <div align="right">

     <form  method="get" action="{{ url('topic/auto-search') }}">
        <div class="" align="left">
            <select class="col-md-3" id='sel_topic' name='sel_topic'>
       <option value='0'>-- Select Topic --</option>
       @foreach($topics as $topic)
         <option value='{{ $topic->id }}'>{{ $topic->topic_name }}</option>
       @endforeach
   </select><span>
       <select class=" col-md-3" id='sel_stand' name='sel_stand'>
       <option value='0'>-- Select Standard --</option>
       @foreach($topics as $topic)
         <option value='{{ $topic->id }}'>{{ $topic->standard_name }}</option>
       @endforeach
   </select>
     <select class="col-md-3" id='sel_sub' name='sel_sub'>
       <option value='0'>-- Select Subject --</option>
       @foreach($topics as $topic)
         <option value='{{ $topic->id }}'>{{ $topic->subject_name }}</option>
       @endforeach
   </select>
    </span>


             <input type="text"  name="search"  id="search">
            <button type="submit" class="btn btn-outline-secondary" name="searchbutton"><i class="fa fa-search"></i></button>&nbsp;&nbsp;


    <a class="btn btn-small btn-primary pull-right" style="margin-top: 5px;" href="{{ URL::to('topic/create') }}"><i class="fa fa-plus"></i>&nbsp;ADD</a>
</div>
</form>
</div>
<div class="">
    <br><br>
<table class="table table-striped table-bordered">
    <thead>
        <tr>
            <td>ID</td>
            <td>Topic Name</td>
            <td>Standard</td>
            <td>Subject</td>
            <td>Actions</td>
        </tr>
    </thead>
    <tbody>


--选择主题--
@foreach($topics作为$topic)
{{$topic->topic_name}
@endforeach
--选择标准--
@foreach($topics作为$topic)
{{$topic->standard_name}
@endforeach
--选择主题--
@foreach($topics作为$topic)
{{$topic->subject_name}
@endforeach


身份证件 主题名称 标准 主题 行动
@mydeen希望它能帮到你!感谢您的帮助,但它会显示错误,如调用未定义的函数App\Http\Controllers\request()Yes Bro或其他方式。我的问题是多个过滤器与search@mydeen对于多个fiter,您可以在控制器中使用条件,因为我在控制器中有答案。调用未定义的函数App\Http\Controllers\request()
<div class="container">
    <div align="right">

     <form  method="get" action="{{ url('topic/auto-search') }}">
        <div class="" align="left">
            <select class="col-md-3" id='sel_topic' name='sel_topic'>
       <option value='0'>-- Select Topic --</option>
       @foreach($topics as $topic)
         <option value='{{ $topic->id }}'>{{ $topic->topic_name }}</option>
       @endforeach
   </select><span>
       <select class=" col-md-3" id='sel_stand' name='sel_stand'>
       <option value='0'>-- Select Standard --</option>
       @foreach($topics as $topic)
         <option value='{{ $topic->id }}'>{{ $topic->standard_name }}</option>
       @endforeach
   </select>
     <select class="col-md-3" id='sel_sub' name='sel_sub'>
       <option value='0'>-- Select Subject --</option>
       @foreach($topics as $topic)
         <option value='{{ $topic->id }}'>{{ $topic->subject_name }}</option>
       @endforeach
   </select>
    </span>


             <input type="text"  name="search"  id="search">
            <button type="submit" class="btn btn-outline-secondary" name="searchbutton"><i class="fa fa-search"></i></button>&nbsp;&nbsp;


    <a class="btn btn-small btn-primary pull-right" style="margin-top: 5px;" href="{{ URL::to('topic/create') }}"><i class="fa fa-plus"></i>&nbsp;ADD</a>
</div>
</form>
</div>
<div class="">
    <br><br>
<table class="table table-striped table-bordered">
    <thead>
        <tr>
            <td>ID</td>
            <td>Topic Name</td>
            <td>Standard</td>
            <td>Subject</td>
            <td>Actions</td>
        </tr>
    </thead>
    <tbody>