77 lines
1.9 KiB
PHP
Raw Normal View History

2020-01-13 02:56:14 +03:00
<?php
2020-10-14 17:07:59 +03:00
namespace Database\Factories;
2020-01-13 02:56:14 +03:00
2020-10-14 17:07:59 +03:00
use App\Abstracts\Factory;
use App\Models\Setting\Currency as Model;
2020-01-13 02:56:14 +03:00
2020-10-14 17:07:59 +03:00
class Currency extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
2020-01-13 02:56:14 +03:00
2020-10-14 17:07:59 +03:00
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$currencies = config('money');
2020-01-21 13:21:03 +03:00
2020-10-14 17:07:59 +03:00
Model::pluck('code')->each(function ($db_code) use (&$currencies) {
unset($currencies[$db_code]);
});
2020-01-21 13:21:03 +03:00
2020-10-14 17:07:59 +03:00
$random = $this->faker->randomElement($currencies);
2020-01-13 02:56:14 +03:00
2020-10-14 17:07:59 +03:00
$filtered = array_filter($currencies, function ($value) use ($random) {
return ($value['code'] == $random['code']);
});
2020-01-13 02:56:14 +03:00
2020-10-14 17:07:59 +03:00
$code = key($filtered);
$currency = $filtered[$code];
2020-01-13 02:56:14 +03:00
2020-10-14 17:07:59 +03:00
return [
'company_id' => $this->company->id,
'name' => $currency['name'],
'code' => $code,
'rate' => $this->faker->randomFloat($currency['precision'], 1, 10),
'precision' => $currency['precision'],
'symbol' => $currency['symbol'],
'symbol_first' => $currency['symbol_first'],
'decimal_mark' => $currency['decimal_mark'],
'thousands_separator' => $currency['thousands_separator'],
'enabled' => $this->faker->boolean ? 1 : 0,
];
}
2020-01-13 02:56:14 +03:00
2020-10-14 17:07:59 +03:00
/**
* Indicate that the model is enabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function enabled()
{
2020-10-15 00:08:41 +03:00
return $this->state([
'enabled' => 1,
]);
2020-10-14 17:07:59 +03:00
}
2020-01-13 02:56:14 +03:00
2020-10-14 17:07:59 +03:00
/**
* Indicate that the model is disabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function disabled()
{
2020-10-15 00:08:41 +03:00
return $this->state([
'enabled' => 0,
]);
2020-10-14 17:07:59 +03:00
}
}