Save transactions by moving them.

This commit is contained in:
James Cole
2015-07-10 20:48:45 +02:00
parent e89d613b7e
commit aa5e313b92
6 changed files with 26 additions and 8 deletions

View File

@@ -46,11 +46,17 @@ class AccountRepository implements AccountRepositoryInterface
/**
* @param Account $account
* @param Account $moveTo
*
* @return boolean
*/
public function destroy(Account $account)
public function destroy(Account $account, Account $moveTo = null)
{
if (!is_null($moveTo)) {
// update all transactions:
DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]);
}
$account->delete();
return true;

View File

@@ -26,10 +26,11 @@ interface AccountRepositoryInterface
/**
* @param Account $account
* @param Account $moveTo
*
* @return boolean
*/
public function destroy(Account $account);
public function destroy(Account $account, Account $moveTo = null);
/**
* @param array $types