Skip to content

Instantly share code, notes, and snippets.

@RakibSiddiquee
Created May 18, 2017 09:11
Show Gist options
  • Save RakibSiddiquee/8d3573c094e22517b909c9d500cc11a7 to your computer and use it in GitHub Desktop.
Save RakibSiddiquee/8d3573c094e22517b909c9d500cc11a7 to your computer and use it in GitHub Desktop.
Get last 7 days data from database order by relation table's field
<?php
public function test(){
$days = new Carbon();
$bn_contents = BnContent::with('category','subcategory','content_meta')
->leftJoin('bn_content_metas', 'bn_contents.content_id', '=', 'bn_content_metas.content_id')
->where('bn_contents.created_at', '<', $days->subDays(7)->toDateTimeString())
->where('bn_contents.status', 1)->where('bn_contents.deletable', 1)
->orderBy('bn_content_metas.total_hit','desc')->take(5)->get();
return ($bn_contents);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment