Skip to content

Instantly share code, notes, and snippets.

@nivv
Created January 17, 2016 09:25
Show Gist options
  • Save nivv/2620b1084079119f859d to your computer and use it in GitHub Desktop.
Save nivv/2620b1084079119f859d to your computer and use it in GitHub Desktop.
<?php
class ArticlesController extends ApiController
{
// Like this
/**
* Store a newly created resource in storage.
*
* @param \App\Http\Requests\CreateArticleRequest $request
* @param \App\Repositories\ArticleRepository $articleRepository
* @return \Illuminate\Http\Response
*/
public function store(CreateArticleRequest $request, ArticleRepository $articleRepository)
{
$article = $articleRepository->store($request);
return $this->respondWithItem($article, new ArticleTransformer);
}
//Or like this
/**
* Store a newly created resource in storage.
*
* @param \App\Http\Requests\CreateArticleRequest $request
* @return \Illuminate\Http\Response
*/
public function store(CreateArticleRequest $request)
{
$article = new Article;
$article->fill($request->except('published_at'));
$article->published_at = null;
$article->save();
return $this->respondWithItem($article, new ArticleTransformer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment