PHP code example of swalbrun / filament-regex-import
1. Go to this page and download the library: Download swalbrun/filament-regex-import 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/ */
public function propertyMapping(): Collection
{
return collect([
'name' => '/(user|first|last)?name)/i',
'email' => '/(E(-|_)?)?Mail/i',
]);
}
public function uniqueColumns(): array
{
return [
'email',
];
}
public function relatingClosures(): Collection
{
return collect([
fn (User $user, Role $role) => $user->roles()->saveMany([$role]),
fn (User $user) => event(new UserImported($user)),
// Only gets called if a user, role and post with the matching type has been found by import
function (User $user, Role $role, Post $post) {
if ($role->is('user')) {
$user->post()->associate($post)->save();
}
};
]);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.