Reputation: 9
I have the following structure of the table:
`id` int(10) UNSIGNED NOT NULL,
`user_id` int(10) UNSIGNED NOT NULL,
`order` int(11) NOT NULL,
`category` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL
I have five confirm records in table where i am querying table like this :
$recommended = App\Recommend::where('category', '=', 'editorpicks');
But the result comes empty, Let me paste the column name and value against it straight from DB.
column name : category
value : editorpicks
.
Why its not working.
I have tried it in tinker
also.
Upvotes: 0
Views: 480
Reputation: 5367
App\Recommend::where('category', 'editorpicks')->get();
Note, you don't need to use "=" in where, if no conditional is provided, the where
clause will default to equals
. get()
grabs the collection. You could also do first()
to grab first single record, last()
, find($id)
, etc.
It's also good practice to namespace the model as well. So add use App\Recommend
to top of controller (I'll assume this already makes sense) and then just use $recommended = Recommend::where(...
. Keep things clean.
Upvotes: 1