Fix use of transformer.

This commit is contained in:
James Cole 2018-02-17 12:24:29 +01:00
parent 23e540a57a
commit 60b225d61c
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
2 changed files with 15 additions and 6 deletions

View File

@ -37,6 +37,7 @@ use League\Fractal\Manager;
use League\Fractal\Resource\Item;
use League\Fractal\Serializer\DataArraySerializer;
use Preferences;
use Symfony\Component\HttpFoundation\ParameterBag;
use URL;
use View;
@ -176,7 +177,10 @@ class BillController extends Controller
$end = session('end');
$pageSize = intval(Preferences::get('listPageSize', 50)->data);
$paginator = $repository->getPaginator($pageSize);
$transformer = new BillTransformer($start, $end);
$parameters = new ParameterBag();
$parameters->set('start', $start);
$parameters->set('end', $end);
$transformer = new BillTransformer($parameters);
/** @var Collection $bills */
$bills = $paginator->getCollection()->map(
function (Bill $bill) use ($transformer) {
@ -238,7 +242,10 @@ class BillController extends Controller
$manager->parseIncludes(['attachments']);
// Make a resource out of the data and
$resource = new Item($bill, new BillTransformer($start, $end), 'bill');
$parameters = new ParameterBag();
$parameters->set('start', $start);
$parameters->set('end', $end);
$resource = new Item($bill, new BillTransformer($parameters), 'bill');
$object = $manager->createData($resource)->toArray();
// use collector:

View File

@ -120,6 +120,8 @@ $factory->define(
function (Faker\Generator $faker) {
return [
'id' => $faker->numberBetween(1, 10),
'created_at' => new Carbon,
'updated_at' => new Carbon,
'user_id' => 1,
'name' => $faker->words(3, true),
'match' => $faker->words(3, true),