Skip to content

Instantly share code, notes, and snippets.

@HORKimhab
Last active October 4, 2022 08:33
Show Gist options
  • Save HORKimhab/1f296648969c689f719d9f13cf9af2bc to your computer and use it in GitHub Desktop.
Save HORKimhab/1f296648969c689f719d9f13cf9af2bc to your computer and use it in GitHub Desktop.
Call seeder in Laravel without Model and use Faker
<?php
namespace Database\Seeders;
use Faker\Generator;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class PartNumberFinalDiscountSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$faker = app(Generator::class);
Schema::disableForeignKeyConstraints();
for ($i = 0; $i < 50; $i++) {
DB::table('part_number_final_discounts')->insert([
'product_number_id' => $faker->numberBetween(1, 50),
'processing_id' => $faker->numberBetween(1, 50),
'discount_amount' => $faker->randomFloat(2),
]);
}
Schema::enableForeignKeyConstraints();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment