1. Go to this page and download the library: Download inlayphp/imports 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/ */
inlayphp / imports example snippets
namespace App\Imports;
use App\Models\User;
use App\Validation\UserRules;
use Inlay\Imports\ImportColumn;
use Inlay\Imports\Importer;
final class UserImporter extends Importer
{
public function validation(): string
{
return UserRules::class;
}
public function columns(): array
{
return [
ImportColumn::make('name')->'mode'] ?? null) === 'upsert' ? 'update' : 'create';
}
public function resolveRecord(array $data, array $options): ?User
{
return User::query()->where('email', $data['email'])->first();
}
public function authorize(array $data, mixed $record, array $options): bool
{
return $options['user']->can($record ? 'update' : 'create', $record ?? User::class);
}
public function persist(array $data, mixed $record, array $options): User
{
$user = $record ?? new User;
$user->fill($data)->save();
return $user;
}
}