“未定义的属性:Larapack \ DoctrineSupport \ Connections \ MySqlConnection :: $ id”

时间:2019-02-26 09:05:52

标签: laravel-5.7

我已经创建了搜索框,我想搜索位置。我不知道为什么id出现错误,请帮助我

controller.php

 public function index()
    {
        $states = HOStateMaster::getAllState();
        return view('vendor/voyager/Ho/index')->with('states',$states);
    }

    public function search(Request $request){

        $search = $request->get('search');
        $states = DB::table('state_city_master')->where('location','like','%'.$search.'%');
        return view('vendor/voyager/Ho/index')->with('states',$states);
    }

blade.php

<div class="search-container">
<form method="GET" action="{{ route('state-master.search') }}">
<div style="display:inline-flex"><input type="text" name="search" class="form-control"><button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button></div>
</form>
</div>
</div>
<div class="card" >
  <div class="card-body">
<table class="table striped" style="overflow-x:auto!important;">
  <thead class="" style="background-color:black;">
    <tr> 
      <th scope="col">{{ "Id" }}</th>
      <th scope="col">{{ "Location" }}</th>
      <th scope="col">{{ "Posted Date" }}</th>
      <th scope="col">{{ "Action" }}</th>
    </tr>
  </thead>
  <tbody>
   @foreach($states as $key => $state)
    <tr class="@cbdms_details.IsOdd("odd","even")>
      <th scope="row">{{ $state->id }}</th>
      <td>{{ $state->location }}</td>
      <td>{{ date('Y-m-d',strtotime($state->created_at)) }}</td>
      <td>

错误屏幕截图

demo link

1 个答案:

答案 0 :(得分:0)

您忘记了->get()

public function search(Request $request){

    $search = $request->get('search');
    $states = DB::table('state_city_master')->where('location','like','%'.$search.'%')->get();
    return view('vendor/voyager/Ho/index')->with('states',$states);
}