1

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');
}
}
blastme
  • 391
  • 7
  • 19
  • 37

1 Answers1

1

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');
Ritesh Khatri
  • 1,253
  • 13
  • 29
  • sorry to disturb you again but why is my home.blade.php only displaying yes for the hire_status when one of my datas is no – blastme Oct 31 '17 at 08:52
  • sorry i had lunch. because you are retrieving only those records which have hire_status only yes, `$data1 = DB::table('hires')->where('hire_status','Yes')->get();` see your where condition `where('hire_status','Yes')` so that it will not fetch the data with hire status No. – Ritesh Khatri Oct 31 '17 at 09:23
  • Yup that is what I want. Hmm maybe I give you an example of what happen, jack is hired so he is under yes, but jane is not hired so she is under no but when I see the whole view, they show me both jane and jack are hired(both are yes) – blastme Oct 31 '17 at 09:26
  • yup because the queries are seperate. thats why. you can use join query for retrieve only those which have yes. join the both table in one query – Ritesh Khatri Oct 31 '17 at 09:27
  • Wait do you understand what I mean? I just want to see yes result but one of the user is no, and in that result that user is being shown and is under yes even though it original is no – blastme Oct 31 '17 at 09:29
  • So I need to join both personal_info table and hires table together inside the HomeController? – blastme Oct 31 '17 at 09:30
  • [Joining tables] (https://stackoverflow.com/questions/23328301/laravel-eloquent-left-join-where-null) you can find in laravel tutorials also. – Ritesh Khatri Oct 31 '17 at 09:31
  • Yup just saw it so all I have to do is just join personal_info and hires table together inside the HomeController? Is it? – blastme Oct 31 '17 at 09:32
  • yup... absolutely – Ritesh Khatri Oct 31 '17 at 09:32
  • and if any query then google and stackoverflow are 24*7 with us :) – Ritesh Khatri Oct 31 '17 at 09:33
  • I have tried doing by using this but it gave me the same result, " $data1 = DB::table('hires') ->join('personal_infos', 'personal_infos.id', '=', 'hires.user_id') ->select('hires.hire_status') ->where('hire_status','Yes') ->get();" – blastme Oct 31 '17 at 09:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/157871/discussion-between-rits-and-blastme). – Ritesh Khatri Oct 31 '17 at 09:44
  • If I remove the where part I will get all no so I am kind of confused what is happening, is it my home.blade.php problem – blastme Oct 31 '17 at 09:44
  • sorry about that just reach home, shall we continue in chat? @Rits – blastme Oct 31 '17 at 11:06