diff --git a/config/laravel_csv.php b/config/laravel_csv.php index 6762f98..54aebbb 100644 --- a/config/laravel_csv.php +++ b/config/laravel_csv.php @@ -14,4 +14,18 @@ | */ '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, ]; diff --git a/resources/views/livewire/tailwindcss/csv-importer.blade.php b/resources/views/livewire/tailwindcss/csv-importer.blade.php index 0c17462..e2736db 100644 --- a/resources/views/livewire/tailwindcss/csv-importer.blade.php +++ b/resources/views/livewire/tailwindcss/csv-importer.blade.php @@ -47,13 +47,15 @@
-

or drag and drop

+

{{ __('or drag and drop') }}

- CSV file up to 50MB + {{ __('CSV file up to :size', [ + 'size' => $fileSize, + ]) }}

diff --git a/src/Facades/LaravelCsv.php b/src/Facades/LaravelCsv.php new file mode 100644 index 0000000..7714600 --- /dev/null +++ b/src/Facades/LaravelCsv.php @@ -0,0 +1,13 @@ + LaravelCsv::formatFileSize( + config('laravel_csv.file_upload_size', 20000) + ), + ]); } protected function validationAttributes() @@ -105,7 +109,7 @@ protected function validationAttributes() protected function rules() { return [ - 'file' => 'required|file|mimes:csv,txt', + 'file' => 'required|file|mimes:csv,txt|max:'. config('laravel_csv.file_upload_size', '20000'), ] + $this->requiredColumns; } diff --git a/src/Http/Livewire/HandleImports.php b/src/Http/Livewire/HandleImports.php index 58b3a04..90f30ca 100644 --- a/src/Http/Livewire/HandleImports.php +++ b/src/Http/Livewire/HandleImports.php @@ -9,7 +9,7 @@ class HandleImports extends Component { /** @var string */ - protected $model; + public $model; /** @var array */ protected $listeners = [ diff --git a/src/LaravelCsvManager.php b/src/LaravelCsvManager.php new file mode 100644 index 0000000..585ad0c --- /dev/null +++ b/src/LaravelCsvManager.php @@ -0,0 +1,28 @@ +registerBladeDirectives(); } + public function registeringPackage() + { + $this->app->bind('laravel-csv', fn() => new LaravelCsvManager); + } + /** * Configure Laravel CSV Blade components * diff --git a/src/helpers.php b/src/helpers.php index 8ea284f..78e4e9e 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -9,7 +9,7 @@ * @param string|null $view * @return string */ - function csv_view_path($view) + function csv_view_path($view): string { return 'laravel-csv::livewire.'.config('laravel_csv.layout').'.'.$view; } diff --git a/tests/CsvImporterTest.php b/tests/CsvImporterTest.php index 506f809..102af16 100644 --- a/tests/CsvImporterTest.php +++ b/tests/CsvImporterTest.php @@ -12,11 +12,6 @@ beforeEach(fn () => $this->actingAs(User::factory()->create())); -it('renders import CSV component', function () { - livewire(CsvImporter::class) - ->assertSuccessful(); -}); - it('renders import CSV component with model', function () { $model = Customer::class; diff --git a/tests/HandleImportsTest.php b/tests/HandleImportsTest.php index a30b9e6..86db53e 100644 --- a/tests/HandleImportsTest.php +++ b/tests/HandleImportsTest.php @@ -4,11 +4,6 @@ use Coderflex\LaravelCsv\Tests\Models\User; use function Pest\Livewire\livewire; -it('renders handle imports component', function () { - livewire(HandleImports::class) - ->assertSuccessful(); -}); - it('renders handle imports component with model', function () { $this->actingAs(User::factory()->create());