Created
January 17, 2016 09:25
-
-
Save nivv/2620b1084079119f859d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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