Example #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $account = Account::where('id', '=', $id)->first();
     if (Request::get('customer_id')) {
         $account->customer_id = Input::get('customer_id');
     }
     if (Request::get('type')) {
         try {
             $type = AccountType::where('name', '=', Input::get('type'))->firstOrFail();
         } catch (ModelNotFoundException $e) {
             return $this->handleInvalidType(Input::get('type'));
         }
         $account->type()->associate($type);
     }
     if (Request::get('balance')) {
         $account->balance = Input::get('balance');
     }
     $account->save();
     return Response::json(array('message' => 'account updated'), 200);
 }
Example #2
0
 protected function createAccount($type = null)
 {
     if (is_null($type)) {
         $type = $this->validTypes[array_rand($this->validTypes)];
     }
     $type = AccountType::where('name', '=', $type)->firstOrFail();
     $account = new Account();
     $account->type()->associate($type);
     $account->user()->associate($this->user);
     $account->balance = round(mt_rand() / mt_getrandmax() * 1000, 2);
     $account->save();
     return $account;
 }