From 8304a44aa4cb85f6d5dff5dbc7e5c79fde5eb1c6 Mon Sep 17 00:00:00 2001 From: Devin <devin@blackhat.co.za> Date: Fri, 12 Oct 2018 00:03:30 +0200 Subject: [PATCH] added more detail to the project page, percentage, number of contributions and total requested --- app/Http/Controllers/FundingController.php | 11 ++++++++++- app/Project.php | 2 +- resources/views/ffs.blade.php | 4 +++- routes/web.php | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/FundingController.php b/app/Http/Controllers/FundingController.php index f9b4275..c0638cb 100644 --- a/app/Http/Controllers/FundingController.php +++ b/app/Http/Controllers/FundingController.php @@ -21,7 +21,16 @@ class FundingController extends Controller public function show($paymentId) { $project = Project::where('payment_id', $paymentId)->first(); + if (!$project) { + abort(404); + } + $contributions = $project->deposits->count(); + $amountReceived = $project->deposits->sum('amount'); + $percentage = round($amountReceived / $project->target_amount * 100); return view('ffs') - ->with('amount_received', $project->deposts->sum('amount')); + ->with('project', $project) + ->with('contributions', $contributions) + ->with('percentage', $percentage) + ->with('amount_received', $amountReceived); } } diff --git a/app/Project.php b/app/Project.php index 1f093f0..c0cd47a 100644 --- a/app/Project.php +++ b/app/Project.php @@ -11,6 +11,6 @@ class Project extends Model */ public function deposits() { - return $this->hasMany(Deposit::class); + return $this->hasMany(Deposit::class, 'payment_id', 'payment_id'); } } diff --git a/resources/views/ffs.blade.php b/resources/views/ffs.blade.php index c221b56..39bee2e 100644 --- a/resources/views/ffs.blade.php +++ b/resources/views/ffs.blade.php @@ -1 +1,3 @@ -{{amount_received}} \ No newline at end of file +XMR {{$amount_received}} / XMR {{$project->target_amount}} Target + +{{$contributions}} contributions made. {{$percentage}}% \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index db0e6df..9479649 100644 --- a/routes/web.php +++ b/routes/web.php @@ -15,4 +15,4 @@ Route::get('/', function () { return view('welcome'); }); -Route::get('project/{paymentId}', ['as' => 'ffs', 'uses' => \App\Http\Controllers\FundingController::class.'@show']); +Route::get('project/{paymentId}', ['as' => 'ffs', 'uses' => FundingController::class.'@show']); -- GitLab