Thursday, September 3, 2015


As i go along with my laravel journey, i found and encountered some errors and this is the one of them: "Undefined property: Illuminate\Database\Query\Builder::$id", i encountered this when i am trying to call a method on a controller, the show method inside a controller of-course there is a one parameter that is a id; and my code will look like this:

$cat = DB::table('category')->select('id','name','description')->where('id', $id)

so i found out that i forgot something, that there is a  method first() function, since i am retrieving a single or one row, in mySQL we can done it like this:

Select id, name From category where id = 1 LIMIT 1; 

so the solution is very simple by simply adding the first() method;

 $cat = DB::table('category')->select('id','name','description')->where('id', $id)->first()


and your good to go!!! Hope this will Help!!!

Happy Coding

1 comments:

  1. Cool blog! Is your theme custom made or did you download it from somewhere? A theme like yours with a few simple adjustments would really make my blog shine. Please let me know where you got your theme. With thanks a fantastic read: 5 Lessons About Encryption Software You Need To Learn Before You Hit 40 & 5 Things You Can Learn About Yourself While How To Encrypt A Password For Freeing In The Mirror.

    ReplyDelete