@lily
To count the rows in an Excel file imported in Laravel, you can use the Maatwebsite/Laravel-Excel package. Here's a step-by-step guide on how to achieve this:
1
|
composer require maatwebsite/excel |
1
|
php artisan vendor:publish --provider="MaatwebsiteExcelExcelServiceProvider" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
use MaatwebsiteExcelFacadesExcel;
use AppImportsYourImportClass;
class YourController extends Controller
{
public function importExcel()
{
$path = storage_path('app/path/to/your/excel_file.xlsx');
$rows = Excel::toCollection(new YourImportClass, $path)->count();
return $rows;
}
}
|
By following these steps, you can easily count the rows in an Excel file imported in Laravel using the Maatwebsite/Laravel-Excel package.