laravel 8
This commit is contained in:
@ -1,36 +1,132 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\Setting\Tax;
|
||||
use Faker\Generator as Faker;
|
||||
namespace Database\Factories;
|
||||
|
||||
$user = User::first();
|
||||
$company = $user->companies()->first();
|
||||
use App\Abstracts\Factory;
|
||||
use App\Models\Setting\Tax as Model;
|
||||
|
||||
$factory->define(Tax::class, function (Faker $faker) use ($company) {
|
||||
setting()->setExtraColumns(['company_id' => $company->id]);
|
||||
class Tax extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Model::class;
|
||||
|
||||
$types = ['normal', 'inclusive', 'compound', 'fixed', 'withholding'];
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
$types = ['normal', 'inclusive', 'compound', 'fixed', 'withholding'];
|
||||
|
||||
return [
|
||||
'company_id' => $company->id,
|
||||
'name' => $faker->text(15),
|
||||
'rate' => $faker->randomFloat(2, 10, 20),
|
||||
'type' => $faker->randomElement($types),
|
||||
'enabled' => $faker->boolean ? 1 : 0,
|
||||
];
|
||||
});
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'name' => $this->faker->text(15),
|
||||
'rate' => $this->faker->randomFloat(2, 10, 20),
|
||||
'type' => $this->faker->randomElement($types),
|
||||
'enabled' => $this->faker->boolean ? 1 : 0,
|
||||
];
|
||||
}
|
||||
|
||||
$factory->state(Tax::class, 'enabled', ['enabled' => 1]);
|
||||
/**
|
||||
* Indicate that the model is enabled.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
||||
*/
|
||||
public function enabled()
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
return [
|
||||
'enabled' => 1,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
$factory->state(Tax::class, 'disabled', ['enabled' => 0]);
|
||||
/**
|
||||
* Indicate that the model is disabled.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
||||
*/
|
||||
public function disabled()
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
return [
|
||||
'enabled' => 0,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
$factory->state(Tax::class, 'normal', ['type' => 'normal']);
|
||||
/**
|
||||
* Indicate that the model type is normal.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
||||
*/
|
||||
public function normal()
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
return [
|
||||
'type' => 'normal',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
$factory->state(Tax::class, 'inclusive', ['type' => 'inclusive']);
|
||||
/**
|
||||
* Indicate that the model type is inclusive.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
||||
*/
|
||||
public function inclusive()
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
return [
|
||||
'type' => 'inclusive',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
$factory->state(Tax::class, 'compound', ['type' => 'compound']);
|
||||
/**
|
||||
* Indicate that the model type is compound.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
||||
*/
|
||||
public function compound()
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
return [
|
||||
'type' => 'compound',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
$factory->state(Tax::class, 'fixed', ['type' => 'fixed']);
|
||||
/**
|
||||
* Indicate that the model type is fixed.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
||||
*/
|
||||
public function fixed()
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
return [
|
||||
'type' => 'fixed',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
$factory->state(Tax::class, 'withholding', ['type' => 'withholding']);
|
||||
/**
|
||||
* Indicate that the model type is normal.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
||||
*/
|
||||
public function withholding()
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
return [
|
||||
'type' => 'withholding',
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user