1. Go to this page and download the library: Download w360/import-gpg-excel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
w360 / import-gpg-excel example snippets
namespace App\Imports;
use Illuminate\Support\Collection;use Illuminate\Support\Facades\Hash;
use Maatwebsite\Excel\Concerns\ToModel;
use App\Models\User;
use W360\ImportGpgExcel\Imports\GpgImport;
class UsersImport extends GpgImport
{
/**
* if the object is returned, the row is considered
* to have been imported successfully,
* otherwise the row will be marked as failed in the report
*
* @param array | Collection $row
* @return mixed
* @throws Exception
*/
public function row($row)
{
$findUser = User::where('identifier', $row['identifier'])->first();
if(!$findUser){
return User::create([
'name' => $row['name'],
'email' => $row['email'],
'password' => Hash::make($row['password']),
]);
}
return $this->exception('User '.$row['identifier'].' already exists');
}
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use W360\ImportGpgExcel\Facades\ImportGPG;
use W360\ImportGpgExcel\Models\Import;
use App\Imports\UsersImport;
class TestController extends Controller
{
/**
* allows you to upload a file and associate
* it with an import file that will be
* executed asynchronously via cron jobs
*
* @param Request $request
*/
private function upload(Request $request){
if($request->hasFile('file')){
ImportGPG::create($request->file, 'default', UsersImport::class);
}
}
/**
* show the detail of all imported files
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function showImportFiles(){
return Import::all();
}
/**
* show current import file details
*
* @return mixed
*/
public function showCurrentImport(){
return Import::where('model_type', UsersImport::class)
->where('state', 'processing')
->first();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.