Laravel Run Seed
#All of them
php artisan db:seed
#One class
php artisan db:seed --class=UserSeeder
Eranot
#All of them
php artisan db:seed
#One class
php artisan db:seed --class=UserSeeder
php artisan make:seeder NameOfTheSeeder
php artisan make:seeder UsersTableSeeder
<?php
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('users')->insert([
'name' => Str::random(10),
'email' => Str::random(10).'@gmail.com',
'password' => Hash::make('password'),
]);
}
}
make DatabaseSeerder class and call function with seeder Array
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$this->call([
UserSeeder::class
AdminSeeder::class
]);
}
}
<?php
use App\Models\Eloquent\DriversModel;
use Illuminate\Database\Seeder;
class DriversSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
if (Schema::hasTable("drivers")) {
// Nechta generatsiya qilish kerak bo`lsa belgilanadi default 10 tani tashkil qiladi
$count = (int)$this->command->ask('Necha dona Ustun qo`shishim kerak?', 10);
for ($i=1; $i < $count; $i++) {
DriversModel::query()->updateOrCreate(['id' => $i], [
'car_number' => ''.$i.'A365EA',
'trailer_number' => 'a5s6d4321c2a6',
'technical_passport' => 'asd56a5sa6f5',
'full_name' => 'Akbarali'.$i.'',
'passport' => '{"0": "test'.$i.'.png", "1": "test1'.$i.'.png"}',
'license_limitation' => '6567965',
'license' => '{"0": "test'.$i.'.png", "1": "test1'.$i.'.png"}',
'rate' => '54546'.$i,
'user_id' => '3',
]);
$this->command->info("{$i} ustun qo'shildi.");
}
$this->command->info("Jami {$i} ustun qo'shildi.");
}
}
}