<?php
namespace Database\Seeders;
use App\Imports\PesertasImport;
use App\Models\Pelatihan;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Storage;
use Maatwebsite\Excel\Facades\Excel;
class ImportPesertaSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$instruktur = User::where('role','instruktur')->first();
$files = Storage::files("jawaban-google-form");
foreach ($files as $file) {
if(str_contains($file,".xlsx") && !str_contains($file,"~$")){
//move /storage/app/sample/photo-1561070791-2526d30994b5.jpeg to /storage/app/public/pelatihan/photo-1561070791-2526d30994b5.jpeg
Storage::move('sample/photo-1561070791-2526d30994b5.jpeg','public/pelatihan/photo-1561070791-2526d30994b5.jpeg');
Pelatihan::create([
'title' => str_replace("(Jawaban)","",str_replace(".xlsx","",basename($file))),
'start_date' => date("Y-m-02"),
'end_date' => date("Y-m-14"),
'description' => str_replace("(Jawaban)","",str_replace(".xlsx","",basename($file))),
'user_id'=>$instruktur->id,
'thumbnail' => 'public/pelatihan/photo-1561070791-2526d30994b5.jpeg'
]);
$model = new PesertasImport();
$model->fileName = $file;
try {
Excel::import($model, $file);
} catch (\Throwable $th) {
dd($file,$th);
}
}
}
}
}
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]