Skip to content

Instantly share code, notes, and snippets.

@mass6
mass6 / SidebarComposer.php
Created February 25, 2015 10:39
Returns the related a an aggregate list of related (many-many) models by the count of related models. Fx. return all tags in order of amount of associated posts they have.
$tagsList = $this->tag->select(DB::raw('tags.name, count(tags.id) as occurrences'))
->join('post_tag', 'tags.id', '=', 'post_tag.tag_id')
->join('posts', 'posts.id', '=', 'post_tag.post_id')
->groupBy('tag_id')
->orderBy('occurrences', 'desc')
->limit(12)
->get();
@mass6
mass6 / Report.php
Created March 29, 2014 12:12
To become Factory
if(file_exists('protected/components/' . $this->reportName . '.php')){
$reportModel = new $this->reportName;
$this->reportTitle = $reportModel->reportTitle;
$this->_report = $reportModel->getReport();
$this->reportContent = $this->_report->report;
$this->downloadableReport = $this->_report->reportGrid;
} else {
$this->reportContent = 'No report of named type ' . $this->reportName ;
}