Last active
February 8, 2017 15:26
-
-
Save zackify/7fe0603a22515d014f7e3f43e2dac373 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
public function __construct(Book $bookModel, BookTransformer $transformer) | |
{ | |
parent::__construct(); | |
$this->transmit = [ | |
'transformer' => $transformer, | |
'model' => $bookModel, | |
]; | |
} | |
/** | |
* Show a list of Books. | |
* | |
* @param Request $request | |
* @return mixed | |
*/ | |
public function index(Request $request) | |
{ | |
return $this->respondWithPaginatedCollection(); | |
//defaults to this->transmit->model as the $optionalModelItem. The transformer is already set too in constructor | |
return $this->respondWithPaginatedCollection($optionalModelItem); | |
/* inside your respond with methods they will run | |
$includes = $this->transmit->transformer->getEagerLoads($this->fractal->getRequestedIncludes()); | |
$items = $this->eagerLoadIncludes($this->transmit->model, $includes); | |
$items = $this->applyParameters($items, request()->query); | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One thing that might be a problem. In some controllers I end up using two transformers. For example: the Job controller. In the index and show methods I use the JobTransformer but in the store and update methods I use the JobBuilderTransformer.
Those could (and maybe should) be split into two different controllers: JobController and JobBuilderController. So maybe it is not something to worry about.
Maybe this even enforces keeping controllers focused on one task.