Exemple #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['body' => 'required|string', 'description' => 'required|string', 'tags' => 'required|array']);
     $tags = array_map(function ($tag) {
         return new Tag(['body' => $tag]);
     }, $request->input('tags'));
     $quote = new Quote();
     $quote->approved = false;
     $quote->body = $request->input('body');
     $quote->description = $request->input('description');
     // FIXME: Replace with currently auth'd member
     $quote->member_id = $request->member->id;
     $quote->save();
     $quote->tags()->saveMany($tags);
     return new JsonResponse($quote, Response::HTTP_CREATED);
 }