Last active
July 28, 2020 23:55
-
-
Save jarod51/80f41fc7d6cc3c784c232a394f9c0cc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Carbon\Carbon as Carbon; | |
use Faker\Factory as Faker; | |
use Illuminate\Database\Seeder; | |
use Illuminate\Support\Facades\DB; | |
/** | |
* Class BrandTableSeeder | |
*/ | |
class BrandTableSeeder extends Seeder { | |
public function run() { | |
if (env('DB_CONNECTION') == 'mysql') { | |
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); | |
} | |
if (env('DB_CONNECTION') == 'mysql') { | |
DB::table(config('app.brands_table'))->truncate(); | |
} elseif (env('DB_CONNECTION') == 'sqlite') { | |
DB::statement('DELETE FROM '.config('app.brands_table')); | |
} else { | |
//For PostgreSQL or anything else | |
DB::statement('TRUNCATE TABLE '.config('app.brands_table').' CASCADE'); | |
} | |
DB::table(config('app.brands_table'))->delete(); | |
$faker = Faker::create(); | |
// Add some brands | |
$brands = [ | |
['name' => 'Toyota', 'resume' => $faker->paragraph(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()], | |
['name' => 'Opel', 'resume' => $faker->paragraph(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()], | |
['name' => 'Chevrolet', 'resume' => $faker->paragraph(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()], | |
// many more... | |
]; | |
DB::table(config('app.brands_table'))->insert($brands); | |
if (env('DB_CONNECTION') == 'mysql') { | |
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment