unable to pluck a column out of a query result in Laravel

I have the following query to bring top 5 contributers : $top_cont = DB::table(‘quests’) ->select(‘user_id’, DB::raw(‘count(*) as contributions’)) ->whereDate(‘created_at’, ‘>=’, now()->startOfDay()) ->take(5) ->groupBy(‘user_id’) ->orderBy(‘contributions’, ‘desc’) ->get(); The following is the array output: array:2 [▼ 0 => {#379 ▼ +”user_id”: 2 +”contributions”: 2 } 1 => {#380 ▼ +”user_id”: 8 +”contributions”: 1 } ] I’m trying…

Query that brings the most occurrences of a certain field in Laravel

I have the following query : $top_cont = DB::table(‘quests’) ->whereBetween(‘created_at’, [ Carbon::now()->startOfDay(),Carbon::now()->endOfDay()]) ->take(5) ->get(); The quests table has a user_id column. I’m trying to get the top 5 user_ids who has the most contributions (i.e. has the most number of rows in the quests table for this day). How can I adjust the query to…

Laravel String Validation Failing on “True” and “False”

Recently it came to my attention that using the following validators in laravel don’t work for Boolean like input such as “True” or “False. Although I had a good laugh about it, I am wondering is there any way to have the string validator accept “True” or “False” ‘first_name’ => ‘sometimes|required|string|max:255’, ‘last_name’ => ‘sometimes|required|string|max:255’, If…