Jump to content
Sign in to follow this  
Korferer

Help me understand the non-object error message

Recommended Posts

Hi,

 

This code works (and correctly shows just one result in my view);

$people = DB::table('people')->where('id', '=', $person_id)->get();

But this one doesn't;

$people = DB::table('people')->where('id', $person_id)->first();

And produces the error;

Trying to get property of non-object (View: /media/sf_sandbox/health/app/views/agreement/display.blade.php)

The `people` table just has a few fields of information on the individual with a primary key called `id`.

 

I followed the Laravel guide on select statements. I don't understand what the error is trying to tell me and I don't get why that second statement is wrong. What's so wrong about it? I just want to understand Laravel/Objects better....

 

Thanks

 

Share this post


Link to post
Share on other sites

My guess would be that your condition in the second query doesn't match anything (no row has id=$person_id) so the first method returns false.

 

Verify that $person_id contains a valid ID and matches a row in your database.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.