本文整理汇总了PHP中app\Group::articles方法的典型用法代码示例。如果您正苦于以下问题:PHP Group::articles方法的具体用法?PHP Group::articles怎么用?PHP Group::articles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Group
的用法示例。
在下文中一共展示了Group::articles方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request, Group $group)
{
$validator = Validator::make($request->all(), ['published' => 'required|date', 'title' => 'required|min:3|max:255', 'content' => 'required|min:10', 'comments' => 'required|boolean', 'help' => 'boolean']);
if ($validator->passes()) {
$help = $request->help === 1 && \App\Group::find($group_id)->service_provider === 1;
// TBD check user has write access to group
$article = $group->articles()->create(['allow_comments' => (bool) $request->comments, 'help' => (bool) $help, 'user_id' => Auth::user()->id, 'published_at' => $request->published]);
$content = $this->createArticleContent($article, $request, 'New Article');
if ($content) {
$article->content_id = $content->id;
$article->save();
return $this->respondWithItem($article, new ArticleTransformer());
} else {
return $this->errorInternalError('Could not create article');
}
} else {
return $this->errorValidation($validator->messages());
}
}
示例2: includeArticles
public function includeArticles(Group $group)
{
$articles = $group->articles()->orderBy('published_at', 'desc')->get();
return $this->collection($articles, new ArticleTransformer());
}