- Introduction
- Installation
- Configuration
- Usage
- Testing
- Changelog
- Contributing
- Security Vulnerabilities
- Inspiration
- Credits
- License
Laravel CSV Package is a package created on top of Laravel livewire package, and it handles importing thousands of records without any issues.
You can install the package via composer:
composer require coderflex/laravel-csv
You can publish and run the migrations with:
php artisan vendor:publish --tag="csv-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="csv-config"
This is the contents of the published config file:
return [
/*
|--------------------------------------------------------------------------
| Default Layout
|--------------------------------------------------------------------------
|
| This package came with multiple layouts to serve your need, and
| currently it supports "tailwindcss" and "bootstrap", by default
| the layout is tailwind.
| currently support: "tailwindcss", "bootstrap"
|
*/
'layout' => 'tailwindcss',
/*
|--------------------------------------------------------------------------
| Max Upload File Size
|--------------------------------------------------------------------------
|
| This package came with file validation for uploaded files,
| and by default the file should not be greater than 20MB. If
| you wish to increase/decrease this value, you may change the
| value below.
| Note that the value is defined by "KB".
|
*/
'file_upload_size' => 20000,
];
The layout
option is for choosing which CSS Framework you are using, currently supports only tailwindcss
, and we're working on other CSS frameworks to implement in the future.
The file_upload_size
is for validation rules, and it helps define the file size of the uploaded files, or. You can define this one from livewire config file.
Optionally, you can publish the views using
php artisan vendor:publish --tag="csv-views"
Before Using this command, please take a look at this section below.
Using this package, is really simple, all what you need to do is implementing the component inside your desired file.
<livewire:csv-importer :model="App\Models\YourModel::class"
:columns-to-map="['id', 'name', 'email', 'password']"
:required-columns="['id', 'name', 'email']"
:columns-label="[
'id' => 'ID',
'name' => 'Name',
'email' => 'Email Address',
'password' => 'Password',
]"/>
Props | Type | Description |
---|---|---|
model | string |
Fully qualified name of the model wants to import to |
columns-to-map | array |
Accept Columns need to be imported in the db |
required-columns | array |
Accept Columns need to be required while importing |
columns-label | array |
Accept Column Label of the required columns for the message |
The Component using alpinejs
under the hood, If you want to use add the import button, you may use x-csv-button
component.
<x-csv-button>Import</x-csv-button>
If you want to style it, you can use the class
attribute, or any attribute you want really
<x-csv-button
class="rounded py-2 px-3 bg-indigo-500 ..."
type="button"
....>
{{ __('Import') }}
</x-csv-button>
If you are using this package in a TALL Stack project, (Tailwindcss, Alpinejs, Laravel, Livewire) All what you need to do is publish the vendor views
php artisan vendor:publish --tag="csv-views"
Then compile your assets, to add the additional classes, came with the component.
npm run dev
If you are not using the TALL Stack by default, you may use the csv directives
to add the necessary styles/scripts
<html>
...
<head>
...
@csvStyles
</head>
...
<footer>
...
@csvScripts
</footer>
</html>
This package is using queues, under the hood with PHP Generators, to make it works fast and efficient.
You need first to create the batches table
php artisan queue:batches-table
Then run the migration
php artisan migrate
After that, you need to set up the queues' configuration. You may head into Laravel Queues Documentation to learn more.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
This Package Was Inspired by codecourse video series, and if you want to learn how this package was created, make sure to take a look at this video series
The MIT License (MIT). Please see License File for more information.