SmokeTM
2 months ago

How do I get the max value?

Posted 2 months ago by SmokeTM

Someone could tell me how to do it right? I have a table Video with a foreign key sub_topic_id and I want to get the highest episode number for every video which belongsto subtopic. I tried something like

$videos = Video::with('subtopic')->groupBy('sub_topic_id')->max('episode')->paginate(10);

but that does not work. Someone could help me here please?

EDIT: The video table looks like

id| sub_topic_id| episode
___________________________
1	1		1
2	1 	 	2
3	2             10

Please sign in or create an account to participate in this conversation.