Ad
Factory Same ID For A Column, Auto-incremental, Laravel
I try to give to a column the ID of that row, witch is autoincremental. Right now are random values .
//From Factory
return [
//code...
'register_id' => $faker->unique()->numberBetween($min = 1, $max = 100),
//code...
];
//From Seeder
public function run()
{
factory(App\Person::class, 100)->create();
}
Ad
Answer
I found an answer, here , and I edited for my case.
$autoIncrement = autoIncrement();
$factory->define(Person::class, function (Faker $faker) use ($autoIncrement) {
$autoIncrement->next();
//code
return [
'register_id' => $autoIncrement->current(),
]
});
function autoIncrement()
{
for ($i = 0; $i < 1000; $i++) {
yield $i;
}
}
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad