Пример #1
0
 /**
  * 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
0
 public function includeArticles(Group $group)
 {
     $articles = $group->articles()->orderBy('published_at', 'desc')->get();
     return $this->collection($articles, new ArticleTransformer());
 }