-[](https://packagist.org/packages/coderflexx/laravel-csv)
+[](https://packagist.org/packages/coderflex/laravel-csv)
[](https://github.com/coderflexx/laravel-csv/actions?query=workflow%3Arun-tests+branch%3Amain)
[](https://github.com/coderflexx/laravel-csv/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
-[](https://packagist.org/packages/coderflexx/laravel-csv)
+[](https://packagist.org/packages/coderflex/laravel-csv)
- [Introduction](#introduction)
@@ -66,7 +66,7 @@ return [
| 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"
+ | currently support: "tailwindcss"
|
*/
'layout' => 'tailwindcss',
@@ -124,13 +124,13 @@ Using this package, is really simple, all what you need to do is implementing th
| columns-label |`array` | Accept Column Label of the required columns for the message |
### Button Component
-The Component using `alpinejs` under the hood, If you want to use add the import button, you may use `x-csv-button` component.
+The Component using `alpinejs` under the hood, If you want to use the import button, you may use `x-csv-button` component.
```blade
Import
```
-If you want to style it, you can use the `class` attribute, or any attribute you want really
+If you want to style it, you may use the `class` attribute, or any attribute you want.
```blade
```
### In TALL stack project
-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
+If you are using this package in a [TALL Stack](https://tallstack.dev/) project, (Tailwindcss, Alpinejs, Laravel, Livewire) All what you need to do is publish the vendor views
```bash
php artisan vendor:publish --tag="csv-views"
From 6aac2a4d4087c2ffffb38b5839933fdd4389db2a Mon Sep 17 00:00:00 2001
From: ousid
Date: Sun, 18 Sep 2022 20:16:31 +0100
Subject: [PATCH 2/7] update laravel_csv.php config
---
config/laravel_csv.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/config/laravel_csv.php b/config/laravel_csv.php
index 54aebbb..94154d2 100644
--- a/config/laravel_csv.php
+++ b/config/laravel_csv.php
@@ -10,7 +10,7 @@
| 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"
+ | currently support: "tailwindcss"
|
*/
'layout' => 'tailwindcss',
From fa9760eb0649dd0dba41b230140a9180cbcf85a8 Mon Sep 17 00:00:00 2001
From: ousid
Date: Sun, 18 Sep 2022 21:26:46 +0100
Subject: [PATCH 3/7] update: static analyses checks
---
phpstan.neon.dist | 6 +++++-
src/Http/Livewire/HandleImports.php | 9 ++++++---
src/Jobs/ImportCsv.php | 2 +-
src/LaravelCsvDirectives.php | 23 ++++++++++++++++++++---
src/LaravelCsvServiceProvider.php | 3 +++
src/Utilities/ChunkIterator.php | 5 ++++-
src/helpers.php | 2 +-
7 files changed, 40 insertions(+), 10 deletions(-)
diff --git a/phpstan.neon.dist b/phpstan.neon.dist
index a91953b..fb14673 100644
--- a/phpstan.neon.dist
+++ b/phpstan.neon.dist
@@ -2,7 +2,7 @@ includes:
- phpstan-baseline.neon
parameters:
- level: 4
+ level: 6
paths:
- src
- config
@@ -11,4 +11,8 @@ parameters:
checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false
+ checkGenericClassInNonGenericObjectType: false
+ ignoreErrors:
+ - '#Internal error: Internal error: Target class \[laravel-csv\] does not exist.#'
+ - '#Internal error: Internal error: Target class \[livewire\] does not exist.#'
diff --git a/src/Http/Livewire/HandleImports.php b/src/Http/Livewire/HandleImports.php
index c912f05..e777696 100644
--- a/src/Http/Livewire/HandleImports.php
+++ b/src/Http/Livewire/HandleImports.php
@@ -4,6 +4,9 @@
use function Coderflex\LaravelCsv\csv_view_path;
use Coderflex\LaravelCsv\Models\Import;
+use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Contracts\View\View;
+use Illuminate\Contracts\View\Factory;
use Livewire\Component;
class HandleImports extends Component
@@ -16,12 +19,12 @@ class HandleImports extends Component
'imports.refresh' => '$refresh',
];
- public function mount(string $model)
+ public function mount(string $model): void
{
$this->model = $model;
}
- public function getImportsProperty()
+ public function getImportsProperty(): Collection
{
/** @var \Illuminate\Foundation\Auth\User */
$user = auth()->user();
@@ -34,7 +37,7 @@ public function getImportsProperty()
->get();
}
- public function render()
+ public function render(): View|Factory
{
return view(
csv_view_path('handle-imports')
diff --git a/src/Jobs/ImportCsv.php b/src/Jobs/ImportCsv.php
index dc8dada..d89e046 100644
--- a/src/Jobs/ImportCsv.php
+++ b/src/Jobs/ImportCsv.php
@@ -38,7 +38,7 @@ public function handle()
$affectedRows = $this->model::upsert(
$this->chunk,
['id'],
- collect($this->columns)->diff('id')->keys()->toArray(),
+ collect($this->columns)->diff(['id'])->keys()->toArray(),
);
$this->import->increment('processed_rows', $affectedRows);
diff --git a/src/LaravelCsvDirectives.php b/src/LaravelCsvDirectives.php
index 61309ec..cb24a0e 100644
--- a/src/LaravelCsvDirectives.php
+++ b/src/LaravelCsvDirectives.php
@@ -4,21 +4,38 @@
class LaravelCsvDirectives
{
- public static function csvStyles()
+ /**
+ * Get CSV Styles
+ *
+ * @return string
+ */
+ public static function csvStyles():string|null
{
if (config('laravel_csv.layout') == 'tailwindcss') {
return self::getTailwindStyle();
}
+
+ return self::getTailwindStyle();
}
- public static function csvScripts()
+ /**
+ * Get CSV Scripts
+ *
+ * @return string
+ */
+ public static function csvScripts(): string
{
return <<<'HTML'
HTML;
}
- protected static function getTailwindStyle()
+ /**
+ * Get Tailwind Style Path
+ *
+ * @return string
+ */
+ protected static function getTailwindStyle(): string
{
return <<<'HTML'
diff --git a/src/LaravelCsvServiceProvider.php b/src/LaravelCsvServiceProvider.php
index 31fcd8c..eaec972 100644
--- a/src/LaravelCsvServiceProvider.php
+++ b/src/LaravelCsvServiceProvider.php
@@ -60,7 +60,10 @@ protected function configureComponents(): void
*/
protected function registerLivewireComponents(): void
{
+ /** @phpstan-ignore-next-line */
Livewire::component('csv-importer', CsvImporter::class);
+
+ /** @phpstan-ignore-next-line */
Livewire::component('handle-imports', HandleImports::class);
}
diff --git a/src/Utilities/ChunkIterator.php b/src/Utilities/ChunkIterator.php
index 5ed7233..4fc8f22 100644
--- a/src/Utilities/ChunkIterator.php
+++ b/src/Utilities/ChunkIterator.php
@@ -2,6 +2,7 @@
namespace Coderflex\LaravelCsv\Utilities;
+use Generator;
use Iterator;
/**
@@ -35,8 +36,10 @@ public function __construct(Iterator $iterator, int $chunkSize)
/**
* Chunk the given data
+ *
+ * @return Generator
*/
- public function get()
+ public function get(): Generator
{
$chunk = [];
diff --git a/src/helpers.php b/src/helpers.php
index 78e4e9e..8cdb1d9 100644
--- a/src/helpers.php
+++ b/src/helpers.php
@@ -9,7 +9,7 @@
* @param string|null $view
* @return string
*/
- function csv_view_path($view): string
+ function csv_view_path(string|null $view): string
{
return 'laravel-csv::livewire.'.config('laravel_csv.layout').'.'.$view;
}
From eb2d41ce54c196478dbb093ad73cca4714c603dc Mon Sep 17 00:00:00 2001
From: ousid
Date: Sun, 18 Sep 2022 20:27:28 +0000
Subject: [PATCH 4/7] Fix styling
---
src/Http/Livewire/HandleImports.php | 4 ++--
src/LaravelCsvDirectives.php | 8 ++++----
src/Utilities/ChunkIterator.php | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/Http/Livewire/HandleImports.php b/src/Http/Livewire/HandleImports.php
index e777696..7715978 100644
--- a/src/Http/Livewire/HandleImports.php
+++ b/src/Http/Livewire/HandleImports.php
@@ -4,9 +4,9 @@
use function Coderflex\LaravelCsv\csv_view_path;
use Coderflex\LaravelCsv\Models\Import;
-use Illuminate\Database\Eloquent\Collection;
-use Illuminate\Contracts\View\View;
use Illuminate\Contracts\View\Factory;
+use Illuminate\Contracts\View\View;
+use Illuminate\Database\Eloquent\Collection;
use Livewire\Component;
class HandleImports extends Component
diff --git a/src/LaravelCsvDirectives.php b/src/LaravelCsvDirectives.php
index cb24a0e..f1d9463 100644
--- a/src/LaravelCsvDirectives.php
+++ b/src/LaravelCsvDirectives.php
@@ -6,10 +6,10 @@ class LaravelCsvDirectives
{
/**
* Get CSV Styles
- *
+ *
* @return string
*/
- public static function csvStyles():string|null
+ public static function csvStyles(): string|null
{
if (config('laravel_csv.layout') == 'tailwindcss') {
return self::getTailwindStyle();
@@ -20,7 +20,7 @@ public static function csvStyles():string|null
/**
* Get CSV Scripts
- *
+ *
* @return string
*/
public static function csvScripts(): string
@@ -32,7 +32,7 @@ public static function csvScripts(): string
/**
* Get Tailwind Style Path
- *
+ *
* @return string
*/
protected static function getTailwindStyle(): string
diff --git a/src/Utilities/ChunkIterator.php b/src/Utilities/ChunkIterator.php
index 4fc8f22..1a6012c 100644
--- a/src/Utilities/ChunkIterator.php
+++ b/src/Utilities/ChunkIterator.php
@@ -36,7 +36,7 @@ public function __construct(Iterator $iterator, int $chunkSize)
/**
* Chunk the given data
- *
+ *
* @return Generator
*/
public function get(): Generator
From c6fc7558bec6b23c2d39a5e0a3fb8d25577859fc Mon Sep 17 00:00:00 2001
From: johnwesely
Date: Tue, 27 Sep 2022 07:38:01 -0600
Subject: [PATCH 5/7] Update README.md
---
README.md | 58 ++++++++++++++++++++++++++-----------------------------
1 file changed, 27 insertions(+), 31 deletions(-)
diff --git a/README.md b/README.md
index 89a2892..44588ce 100644
--- a/README.md
+++ b/README.md
@@ -27,7 +27,7 @@
- [License](#license)
## Introduction
-__Laravel CSV__ Package is a package created on top of Laravel [livewire](https://laravel-livewire.com) package, and it handles importing thousands of records without any issues.
+__Laravel CSV__ Package is a package created on top of Laravel [livewire](https://laravel-livewire.com) for easily handling imports with a simple API.
## Installation
@@ -39,20 +39,20 @@ composer require coderflex/laravel-csv
## Configuration
-You can publish and run the migrations with:
+Publish and run the migrations with:
```bash
php artisan vendor:publish --tag="csv-migrations"
php artisan migrate
```
-You can publish the config file with:
+Publish the config file with:
```bash
php artisan vendor:publish --tag="csv-config"
```
-This is the contents of the published config file:
+The following is the contents of the published config file:
```php
@@ -63,10 +63,8 @@ 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"
+ | This package plans on supporting multiple CSS frameworks.
+ | Currently, 'tailwindcss' is the default and only supported framework.
|
*/
'layout' => 'tailwindcss',
@@ -76,20 +74,18 @@ return [
| 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".
+ | The default maximumum file size that can be imported by this
+ | package is 20MB. If you wish to increase/decrease this value,
+ | change the value in KB below.
|
*/
'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 `layout` option is for choosing which CSS framework you are using and currently supports only `tailwindcss`. We are 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](https://github.com/livewire/livewire/blob/master/config/livewire.php#L100) file.
+The `file_upload_size` is for validation rules, and it defines the maximum file size of uploaded files. You may also define this value from the [livewire config](https://github.com/livewire/livewire/blob/master/config/livewire.php#L100) file.
Optionally, you can publish the views using
@@ -102,7 +98,7 @@ php artisan vendor:publish --tag="csv-views"
## Usage
### CSV Importer Component
-Using this package, is really simple, all what you need to do is implementing the component inside your desired file.
+Using this package is a breeze. To implmenent the importer in your project, simply include the following component inside a Blade view.
```blade
Import
```
-If you want to style it, you may use the `class` attribute, or any attribute you want.
+To style the button, use the `class` attribute with Tailwind utility classes.
```blade
```
### In TALL stack project
-If you are using this package in a [TALL Stack](https://tallstack.dev/) project, (Tailwindcss, Alpinejs, Laravel, Livewire) All what you need to do is publish the vendor views
+If you are using this package in a [TALL Stack](https://tallstack.dev/) project, (Tailwindcss, Alpinejs, Laravel, Livewire) publish the vendor views to include Laravel-CSV in your project.
```bash
php artisan vendor:publish --tag="csv-views"
```
-Then compile your assets, to add the additional classes, came with the component.
+Then compile your assets.
```bash
npm run dev
```
### In none TALL Stack project
-If you are not using the TALL Stack by default, you may use the `csv directives` to add the necessary styles/scripts
+If you are not using the TALL Stack, use the `csv directives` to add the necessary styles/scripts.
```blade
@@ -170,19 +166,19 @@ If you are not using the TALL Stack by default, you may use the `csv directives`
```
### Using Queues
-This package is using [queues](https://laravel.com/docs/9.x/queues#main-content), under the hood with [PHP Generators](https://www.php.net/manual/en/language.generators.overview.php), to make it works fast and efficient.
+This package uses [queues](https://laravel.com/docs/9.x/queues#main-content) under the hood with [PHP Generators](https://www.php.net/manual/en/language.generators.overview.php) to make it fast and efficient.
-You need first to create the `batches table`
+Create the `batches table` by running
```bash
php artisan queue:batches-table
```
-Then run the migration
+Then, run the migration.
```
php artisan migrate
```
-After that, you need to set up the queues' configuration.
-You may head into [Laravel Queues Documentation](https://laravel.com/docs/9.x/queues#main-content) to learn more.
+After that, set up the queues' configuration.
+Head to [Laravel Queues Documentation](https://laravel.com/docs/9.x/queues#main-content) to learn more.
## Testing
@@ -204,7 +200,7 @@ Please see [CONTRIBUTING](https://github.com/ousid/.github/blob/main/CONTRIBUTIN
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Inspiration
-This Package Was Inspired by [codecourse](https://codecourse.com) video series, and if you want to learn how this package was created, make sure to take a look at this [video series](https://codecourse.com/subjects/laravel-livewire)
+This Package Was Inspired by [codecourse](https://codecourse.com) video series. If you want to learn how this package was created, make sure to take a look at this [video series](https://codecourse.com/subjects/laravel-livewire)
## Credits
From 209cc877c303f31f16e088f12338acc2a61f639c Mon Sep 17 00:00:00 2001
From: johnwesely
Date: Tue, 27 Sep 2022 07:38:57 -0600
Subject: [PATCH 6/7] Update laravel_csv.php
---
config/laravel_csv.php | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/config/laravel_csv.php b/config/laravel_csv.php
index 94154d2..4576ecd 100644
--- a/config/laravel_csv.php
+++ b/config/laravel_csv.php
@@ -1,5 +1,3 @@
- 'tailwindcss',
@@ -20,11 +16,9 @@
| 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".
+ | The default maximumum file size that can be imported by this
+ | package is 20MB. If you wish to increase/decrease this value,
+ | change the value in KB below.
|
*/
'file_upload_size' => 20000,
From 77c7668010c53cf8aa16e297c8cbec9ed9e76b21 Mon Sep 17 00:00:00 2001
From: askdkc
Date: Wed, 28 Sep 2022 09:20:47 +0900
Subject: [PATCH 7/7] Fixed broken link
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 89a2892..7bd73a4 100644
--- a/README.md
+++ b/README.md
@@ -97,7 +97,7 @@ 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](in-tall-stack-project) below.
+> Before Using this command, please take a look at this [section](#in-tall-stack-project) below.
## Usage