blastme
blastme

Reputation: 429

Property [id] does not exist on this collection instance laravel

I keep getting this error after fixing a new code that I had just put in and I have no idea why it is giving me this error "Property [id] does not exist on this collection instance" which point to the id of my route in home.blade.php. Can someone help me take a look thanks a lot

The part that I added in was the hire_status part and after fixing it, it then gave me this error. home.blade.php

    <table class="table table-bordered">
      <tr>
        <th><strong><big>Name: </big></strong></th>     
        <th><strong><big>Hire Status: </big></strong></th>  
        <th><strong><big>Action: </big></strong></th>
      </tr>
      <td>
      <tr>
        @foreach($data as $value)
      <tr>    
      <th><a href="{{route('user.show',['id'=>$value->id])}}">{{$value->Name}}</a></th>
    <th> 
      @foreach($data1 as $value1)

      {{$value1->hire_status}}

   </th>
      <th><form action="{{  url('/home/'.$value->id.'/delete')  }}" method="get">
        {{ csrf_field() }}
        <button type="submit">Delete</button>
      </form></th>              
      </tr>
      @endforeach
         @endforeach
      </tr>
      </tr>
    </table>

HomeController:

    public function getData(){
        $data['data'] = DB::table('personal_infos')->where('deleted_at',NULL)->get()->sortByDesc('created_at');
        $data1 = DB::table('hires')->where('hire_status','Yes')->get();

        if(count($data)>0){
        return view('home',compact('data','data1'));
    }else{
    return view('home');
}
}

Upvotes: 1

Views: 419

Answers (1)

Ritesh Khatri
Ritesh Khatri

Reputation: 1301

Just remove key from array, you are trying to get data in your view directly so get it directly not to data of data...

$data['data'] = DB::table('personal_infos')->where('deleted_at',NULL)->get()‌​->sortByDesc('create‌​d_at');

change it to,

$data = DB::table('personal_infos')->where('deleted_at',NULL)->get()‌​->sortByDesc('create‌​d_at');

Upvotes: 1

Related Questions