<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alfonsobries / laravel-spreadsheet-importer example snippets
namespace App\Models;
use Alfonsobries\LaravelSpreadsheetImporter\Traits\InteractsWithImporter;
use Alfonsobries\LaravelSpreadsheetImporter\Contracts\Importable;
use Illuminate\Database\Eloquent\Model;
class MyModel extends Model implements Importable
{
use InteractsWithImporter;
/**
* Return the full path of the file that will be imported
* @return string
*/
public function getFileToImportPath() {
// Notice that this line should be adapted to your application, this is an example for
// a path that comes from a file that was stored using the spatie media library package
return $this->getFirstMedia('file')->getPath();
}
/**
* Return the temporaly table name that will be used to store the spreadsheet contents
*
* @return string
*/
public function getTemporalTableName() {
// This is an example you should adapt this line to your own application
// You should create a method that always return the same value for the same model
return sprintf('file_%s', $this->id);
}
php
public function store(Request $request, MyModel $model)
{
$model->addFile($request->file);
\Alfonsobries\LaravelSpreadsheetImporter\Jobs\StartImport::dispatch($model);
// ...The rest of the code
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.