Eloquent where-()-firstOrFail() doesn't return attributes
I'm using Laravel 4.1. I have a table profiles and an class Profiles that extends Eloquent with protected $table = 'profiles'. There's a row in the table with id = 1 and first_name = 'Admin'. I have the following code:
I'm not getting any failure but nor am I getting any of the table attributes. $profile->first_name is null. What am I doing wrong?
when you use where() method use it with model like this
$profile = Profile::where('id','=',1)->firstOrFail();
$profile = Profile::where('id',1)->firstOrFail();
use findOrFail() method if you need to search with id
$profile = Profile::findOrFail(1);
You can use find or findOrFail method, which searches by id columns on it's own.
$profile->findOrFail($id); // or using Facade Profile::findOrFail($id);
Stupid newbie! I wasn't using the static methods, but rather trying to use the methods on an instantiated object.