diff --git a/app/Entities/Invoices/BankAccount.php b/app/Entities/Invoices/BankAccount.php new file mode 100644 index 0000000..ab21340 --- /dev/null +++ b/app/Entities/Invoices/BankAccount.php @@ -0,0 +1,10 @@ +first(); - - if (!is_null($bankAccounts)) { - $bankAccounts = $bankAccounts->value; - $bankAccounts = json_decode($bankAccounts, true); - $bankAccounts = collect($bankAccounts) - ->map(function ($bankAccount) { - return (object) $bankAccount; - }); + $bankAccounts = BankAccount::all(); - if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) { - $editableBankAccount = $bankAccounts[request('id')]; - } - } else { - $bankAccounts = collect([]); + if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) { + $editableBankAccount = BankAccount::find(request('id')); } return view('bank-accounts.index', compact('bankAccounts', 'editableBankAccount')); diff --git a/database/factories/BankAccountFactory.php b/database/factories/BankAccountFactory.php new file mode 100644 index 0000000..917dac3 --- /dev/null +++ b/database/factories/BankAccountFactory.php @@ -0,0 +1,12 @@ +define(BankAccount::class, function (Faker $faker) { + return [ + 'name' => 'Bank '.strtoupper(str_random(4)), + 'number' => str_random(10), + 'account_name' => $faker->name, + ]; +}); diff --git a/database/migrations/2018_10_30_215937_create_bank_accounts_table.php b/database/migrations/2018_10_30_215937_create_bank_accounts_table.php new file mode 100644 index 0000000..79eb4ff --- /dev/null +++ b/database/migrations/2018_10_30_215937_create_bank_accounts_table.php @@ -0,0 +1,35 @@ +increments('id'); + $table->string('name', 60); + $table->string('number', 30); + $table->string('account_name', 60); + $table->string('description')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('bank_accounts'); + } +} diff --git a/tests/Feature/References/ManageBankAccountsTest.php b/tests/Feature/References/ManageBankAccountsTest.php index f9979ab..4cb0a14 100644 --- a/tests/Feature/References/ManageBankAccountsTest.php +++ b/tests/Feature/References/ManageBankAccountsTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature\References; use Tests\TestCase; +use App\Entities\Invoices\BankAccount; use Illuminate\Foundation\Testing\DatabaseMigrations; /**