37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders\Development;
|
|
|
|
use App\Models\Brand;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Uwil\LaravelCommon\Helpers\FileHelper;
|
|
|
|
class BrandSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run(): void
|
|
{
|
|
Schema::disableForeignKeyConstraints();
|
|
DB::table((new Brand())->getTable())->truncate();
|
|
Schema::enableForeignKeyConstraints();
|
|
File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new Brand())->getTable()));
|
|
|
|
Brand::factory(fake()->randomDigitNot([0, 1, 2, 3]))->make()->each(function (Brand $brand) {
|
|
$brand->picture = FileHelper::storeFile(
|
|
new Brand(),
|
|
new \SplFileInfo(
|
|
\resource_path('../database/factories/assets/brands/default-picture-600x350.jpg')
|
|
),
|
|
prefix: $brand->tenant_id
|
|
);
|
|
$brand->save();
|
|
});
|
|
}
|
|
}
|