Sneaky bug. [skip ci]

This commit is contained in:
James Cole 2014-08-05 20:07:02 +02:00
parent 52663de13d
commit 2d0820873a

View File

@ -34,10 +34,11 @@ class EloquentAccountRepository implements AccountRepositoryInterface
* *
* @return \Account|mixed * @return \Account|mixed
*/ */
public function createOrFind($name, \AccountType $type) public function createOrFind($name, \AccountType $type = null)
{ {
$beneficiary = $this->findByName($name);
if (!$beneficiary) { $account = $this->findByName($name, $type);
if (!$account) {
$data = [ $data = [
'name' => $name, 'name' => $name,
'account_type' => $type 'account_type' => $type
@ -46,7 +47,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
return $this->store($data); return $this->store($data);
} }
return $beneficiary; return $account;
} }
/** /**
@ -92,9 +93,10 @@ class EloquentAccountRepository implements AccountRepositoryInterface
* *
* @return mixed * @return mixed
*/ */
public function findByName($name) public function findByName($name, \AccountType $type = null)
{ {
return \Auth::user()->accounts()->where('name', 'like', '%' . $name . '%')->first(); $type = is_null($type) ? \AccountType::where('description', 'Default account')->first() : $type;
return \Auth::user()->accounts()->where('account_type_id',$type->id)->where('name', 'like', '%' . $name . '%')->first();
} }
/** /**