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

问题描述 投票:0回答:1

我已经创建了搜索框,我想搜索位置。我不知道为什么它在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>

错误截图

error

laravel-5.7
1个回答
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);
}
© www.soinside.com 2019 - 2024. All rights reserved.