Commit 40021863 authored by beardedwarrior's avatar beardedwarrior

updated the project resource to add the qrcode and contributions

parent 5e4e0c8e
......@@ -30,23 +30,20 @@ class FundingController extends Controller
/**
* Shows the project based on the payment id
*
* @param Request $request
* @param $paymentId
*
* @return ProjectResource|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function show(Request $request, $paymentId)
{
$project = Project::where('payment_id', $paymentId)->first();
if (!$project) {
abort(404);
}
$project = Project::where('payment_id', $paymentId)->firstOrFail();
if ($request->wantsJson())
{
return new ProjectResource($project);
}
$qrcode = QrCode::format('png')->size(100)->generate($project->uri);
return view('projects.show')
->with('project', $project)
->with('qrcode', $qrcode);
->with('project', $project);
}
}
......@@ -20,6 +20,8 @@ class ProjectResource extends JsonResource
'amount_received' => $this->amount_received,
'target_amount' => $this->target_amount,
'percentage_funded' => $this->percentage_funded,
'qrcode' => ['base64' => base64_encode($this->qrcode)],
'contributions' => $this->contributions,
];
}
}
......@@ -19,6 +19,7 @@ use SimpleSoftwareIO\QrCode\Facades\QrCode;
* @property-read string $uri
* @property-read int $percentage_funded
* @property-read int $contributions
* @property-read string $qrcode
* @method static \Illuminate\Database\Eloquent\Builder|\App\Project whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Project whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Project wherePaymentId($value)
......@@ -53,7 +54,7 @@ class Project extends Model
return $this->deposits->count() ?? 0;
}
public function getQrCodeAttribute() {
public function getQrcodeAttribute() {
return QrCode::format('png')->size(500)->generate($this->uri);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment