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/ */

    

swalbrun / filament-regex-import example snippets


return [
    'accepted_mimes' => [
        'application/vnd.ms-excel',
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'text/csv',
        'text/plain',
        'csv',
    ],
    'mappers' => [
    ],
    'navigation_group' => 'Import',
];

 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();
                }
            };
        ]);
    }