ldc-showroom-bo/database/seeders/Development/FontSeeder.php
2025-05-27 09:11:43 +02:00

38 lines
1.1 KiB
PHP

<?php
namespace Database\Seeders\Development;
use App\Models\Font;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Uwil\LaravelCommon\Helpers\FileHelper;
class FontSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run(): void
{
File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new Font())->getTable()));
collect(['Kanit-Regular.woff2', 'RubikBurned-Regular.woff2'])->each(function (string $font_filename) {
$font_basename = Str::of($font_filename)->explode('.')->get(0);
$font = Font::factory(1)->makeOne();
$font->fill([
'font_name' => Str::slug($font_basename),
'font' => FileHelper::storeFile(
new Font(),
new \SplFileInfo(
\resource_path("../database/factories/assets/fonts/{$font_filename}")
),
prefix: $font->tenant_id
),
]);
$font->saveOrFail();
});
}
}