function storePledge($amount, $type, Project $project, $user) { $pledge = new Pledge(); $pledge->amount = $amount; $pledge->user_id = $user->id; $pledge->type = $type; $pledge->project_id = $project->id; $pledge->save(); }
/** * Check if we can complete a transaction (has it got enough confirms), * if so, set to complete and increment the users balance * @param $t * @param $tran * @return bool */ function completeTransaction($t, Transaction $tran) { if ($t['confirmations'] > 0) { if ($tran->user_id > 0) { $u = $tran->user; DB::table('users')->where('id', $u->id)->increment('balance', $t['amount']); $this->info("Incremented user '{$u->username}' balance by {$tran->amount}"); } else { if ($tran->project_id > 0) { $p = $tran->project; DB::table('projects')->where('id', $p->id)->increment('project_balance', $t['amount']); DB::table('projects')->where('id', $p->id)->increment('total_pledged', $t['amount']); $this->info("Incremented project '{$p->id}' balance by {$tran->amount}"); // track anonymous pledges $pledge = new Pledge(); $pledge->amount = $t['amount']; $pledge->user_id = 0; $pledge->type = "anon"; $pledge->project_id = $p->id; $pledge->save(); } else { return false; } } $tran->confirmations = $t['confirmations']; $tran->status = 'complete'; } $tran->save(); return true; }
/** * Display the specified resource. * * @param $username * @internal param int $id * @return Response */ public function show($username) { try { $user = Auth::user()->with('projects')->where('user_name', $username)->firstOrFail(); } catch (ModelNotFoundException $e) { return Redirect::home(); } // Take the Administrator to the admin panel. if ($user->id == '2') { return redirect('admin'); } $contributions = Pledge::where('user_id', '=', $user->id)->get(); $favourites = Favourite::with('project')->where('user_id', '=', $user->id)->get(); // if it's a regular user, redirect to user's dashboard return view('userpanel.index', compact('user', 'contributions', 'favourites')); }