CurrenciesTableSeeder.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. // Copyright 2019 Hackware SpA <https://hackware.cl>.
  3. // This file is part of "Hackware's Digital Wallet" and licensed under the
  4. // terms of the GNU Affero General Public License version 3, or (at your
  5. // option) a later version. You should have received a copy of this license
  6. // along with the software. If not, see <https://www.gnu.org/licenses/>.
  7. namespace Hawese\Seeds;
  8. use Hawese\Core\Exceptions\ModelObjectNotFoundException;
  9. use Hawese\Wallet\Currency;
  10. use Illuminate\Database\Seeder;
  11. class CurrenciesTableSeeder extends Seeder
  12. {
  13. /**
  14. * Run the database seeds.
  15. *
  16. * @return void
  17. */
  18. public function run()
  19. {
  20. try {
  21. $currency = Currency::findByCode('CLP');
  22. } catch (ModelObjectNotFoundException $ex) {
  23. $currency = new Currency(
  24. ['code' => 'CLP', 'rate' => 1, 'step' => 50]
  25. );
  26. $currency->insert();
  27. }
  28. try {
  29. $currency = Currency::findByCode('USD');
  30. } catch (ModelObjectNotFoundException $ex) {
  31. $currency = new Currency(
  32. ['code' => 'USD', 'rate' => 1, 'step' => 0.01]
  33. );
  34. $currency->insert();
  35. }
  36. }
  37. }