get()->first(); $sessionKey = uniqid('session_key', true); $path = $post->file()->withDeferred($sessionKey)->get()->first()->getPath(); $dividedPath = explode('storage/app', $path); $storageDestinationPath= storage_path("app/extract/".hash('ripemd160', $post->name).'-'.$post->date); if (!\File::exists($storageDestinationPath)) { \File::makeDirectory($storageDestinationPath, 0755, true); } $extractor = new Extractor(); $extractor->extract(storage_path('app/'. $dividedPath[1]), $storageDestinationPath); $filenames = array_diff(scandir($storageDestinationPath), array('.', '..')); foreach ($filenames as $item) { $shop_number = explode(".", $item)[0]; $shop = Shop::where("shop_number", $shop_number)->get()->first(); if ($shop) { $exist = ReportDetail::where('report_id', $id)->where("shop_id", $shop->id)->get(); if ($exist->isEmpty()) { $report_detail = new ReportDetail(); $report_detail->report_id = $id; $report_detail->shop_id = $shop->id; $report_detail->file = explode('storage\app', $storageDestinationPath)[1].'/'.$item; Log::info(explode('storage\app', $storageDestinationPath)[1].'/'.$item); $report_detail->save(); Log::info("saved succesfully"); }else { Log::info("Record exist"); } }else { Log::info("Shop not found"); } } } }