How to Seed Roles to Database using Seeder in Order?
I looked on the Internet and in here, for a way that seeds the roles in the order I want them to be with a specific ID, most results suggested to use Faker randomElements(), but that orders the elements randomly.
I found a way using Factory Sequences, I hope it's the correct way to do so, please share your thoughts about it.
Databases\Seeders\RoleSeeder.php
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\Role;
use Illuminate\Database\Eloquent\Factories\Sequence;
class RoleSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Role::factory(3)->state(new Sequence(
['id' => 1, 'Role' => 'Admin'],
['id' => 2, 'Role' => 'Student'],
['id' => 3, 'Role' => 'Supervisor'],
))->create();
}
}