Jump to content

Help me understand the non-object error message


Recommended Posts



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....




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.

Link to post
Share on other sites


This topic is now archived and is closed to further replies.

  • 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.