/**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $creditcardId = $request->segments()[2];
     $ccUser = CreditCard::find($creditcardId);
     if ($ccUser->user_id != Auth::user()->id) {
         return redirect('profile')->with('danger', 'This credit card is not associated with you.');
     }
     return $next($request);
 }
 public function userFinanceData(Request $request)
 {
     if (Auth::user()) {
         //Update Currency
         DB::table('users')->where('id', Auth::user()->id)->update(['mth_income' => $request->mthlyInc, 'currency' => $request->currency]);
         //Add Cards
         $cardsData = $request->cards;
         //don't forget 'billDue' in card
         if (!empty($cardsData)) {
             foreach ($request->cards as $card) {
                 \App\CreditCard::addCard($card);
             }
             //End foreach
         } else {
             echo "empty request";
         }
     }
 }
 /**
  * Updates a credit card
  *
  * @param $input
  * @param $id
  *
  * @return array
  */
 public function update($input, $id)
 {
     $creditCard = $this->creditCard->findOrFail($id);
     $creditCard->update(['name' => $input->name, 'fee' => $this->money->toStoredMoney($input->fee), 'insurance' => $this->money->toStoredMoney($input->insurance)]);
     return ["id" => $creditCard->id];
 }
 public static function undoRemoveCard(Request $request)
 {
     if (Auth::user()) {
         \App\CreditCard::undoRemoveCard($request->cardId);
     }
 }