public function toArray() { $transformer = $this->getTransformer(); if ($transformer && !$this->toArrayTransformingInProcess) { // this is needed to avoid infinitive loop (Fractal League is also calling toArray) $this->toArrayTransformingInProcess = true; return TransformerManager::transformDataToArray(new $transformer(), $this); } return parent::toArray(); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($userId, $id) { if (Auth::user()->id != $userId) { abort(403); } $user = Auth::user(); $invoice = $user->findInvoiceOrFail($id); $pdf = App::make('dompdf.wrapper'); $pdf->loadHTML($invoice->render(['user' => $user, 'card' => $user->getCard(), 'vendor' => $user->last_name, 'invoiceTransformed' => TransformerManager::transformDataToArray(new InvoiceTransformer($user), $invoice, 'Item')])); return $pdf->stream(); }
public function getInvoices() { if (!$this->stripe_id) { return []; } $invoices = Cache::remember($this->getCacheKeyStripeInvoices(), $this->getCacheExpiresAt(), function () { return $this->invoices(); }); foreach ($invoices as $key => &$invoice) { if (!$invoice->total) { // don't show invoices with zero amount unset($invoices[$key]); } } return TransformerManager::transformDataToArray(new InvoiceTransformer($this), $invoices); }