public static function store($files, $material) { // Making counting of uploaded images $file_count = count($files); // start count how many uploaded $uploadcount = 0; if (!empty($files)) { foreach ($files as $file_path) { if (!empty($file_path)) { $type = File::type($file_path); $mime = File::mimeType($file_path); $extension = File::extension($file_path); $filename = $material->slug . '_' . str_replace(' ', '_', File::name($file_path)) . '.' . $extension; File::move($file_path, storage_path() . '/app/' . $filename); //add file path and thumb path to material_files database $material_file = MaterialFile::firstOrCreate(['original_filename' => File::name($file_path), 'filename' => $filename, 'mime' => $mime]); //add to material file table $material->files()->save($material_file); $uploadcount++; //create thumb MaterialFile::makeThumb($extension, $filename); } } if ($uploadcount == $file_count) { Session::flash('success', 'Upload(s) successfully'); } else { return Redirect::to('material.edit')->withInput(); } } }