本文整理汇总了PHP中app\models\News::with方法的典型用法代码示例。如果您正苦于以下问题:PHP News::with方法的具体用法?PHP News::with怎么用?PHP News::with使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\News
的用法示例。
在下文中一共展示了News::with方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: gridForAdmins
public static function gridForAdmins(&$filter, &$grid)
{
$filter = \DataFilter::source(News::with('createdBy', 'approvedBy', 'status'));
//->where('status_id', '<>', 1)
$filter->add('title', 'Title', 'text');
$filter->add('content', 'Content', 'text');
$filter->add('createdBy.name', 'created_by', 'text');
$filter->add('approvedBy.name', 'approved_by', 'text');
$filter->add('updated_at', 'Last update date', 'daterange')->format('m/d/Y', 'en');
$filter->add('created_at', 'Create date', 'daterange')->format('m/d/Y', 'en');
$filter->submit('search');
$filter->reset('reset');
$filter->build();
$grid = DataGrid::source($filter);
$grid->attributes(array("class" => "table table-striped"));
$grid->add('title', 'Title', true);
$grid->add('updated_at|strtotime|date[m/d/Y]', 'Last update date', true);
$grid->add('created_at|strtotime|date[m/d/Y]', 'Create date', true);
$grid->add('content|strip_tags|substr[0,20]', 'Content');
$grid->add('createdBy.name', 'created_by');
$grid->add('approvedBy.name', 'approved_by');
$grid->add('status.title', 'Status');
$grid->add('view', 'View')->cell(function ($value, $row) {
return '<a class="btn btn-responsive" href="' . url('admin-news/view') . "/" . $row->id . '"><i class="glyphicon glyphicon-eye-open"></i></a>';
});
$grid->add('status.id', 'Approve')->cell(function ($value, $row) {
if ($value == 2) {
return '<a class="btn btn-success btn-responsive" href="' . url('admin-news/approve') . "/" . $row->id . '"><i class="glyphicon glyphicon-ok"></i> Approve</a>';
}
return '';
});
$grid->orderBy('id', 'desc');
$grid->paginate(10);
}
示例2: trendingNews
public function trendingNews($category_id = -1)
{
/*
* the news most visited
*/
if ($category_id < 0) {
$query = News::with('category');
} else {
$category = Category::findOrFail($category_id);
$query = $category->news()->with('category');
}
$trendingNews = $query->where('status', 'active')->orderBy('visit', 'desc')->take(2)->get();
return $this->parseNewsList($trendingNews);
}