Build powerful data-driven interfaces with Laravel, Vue, and DataTables Everything that I’ve seen so far on how to setup DataTables did not yield the kind of results that I needed. I wanted a simple integration of DataTables into my Vue.js/Laravel project, but that was proving more difficult to find than not. This shouldn’t be as difficult as it was made out to be. Let’s take an extremely simple approach to this. Read the previous article on setting up Vue and Vue-Router into the Laravel project. https://blog.devgenius.io/laravel-9-x-with-vue-tailwind-and-vue-router-4c2da39831ea The end goal of this article is to have a functioning DataTables example that

Generate visually rich Excel files directly from your Blade views We covered exporting items from a database table to a sheet, but we haven’t really covered on how to customize that sheet. https://dinocajic.medium.com/laravel-excel-p9-exports-bff04e5c2c14 What we want to do is create a unique way to display content, maybe even injecting some items that are not stored in the database. This involves using blade components in Laravel. One step at a time though. First, we’ll need to create our Exporter. php artisan make:export ViewExporter –model=User This is what the command generates. <?php namespace App\Exports; use App\Models\User; use Maatwebsite\Excel\Concerns\FromCollection; class ViewExporter implements FromCollection

Effortlessly generate Excel files for reliable data sharing I think we’ve gotten to a good point with Imports in the previous 8 articles. It’s time to switch to exporting data into Excel sheets. Laravel-Excel is pretty amazing. It simplifies all of this for us. Since we’ve been working with our User model this whole time, let’s create a quick export. First thing is to create our Exporter and specify that we want to use the User model. php artisan make:export UsersExport –model=User This generates a new file and a new directory under the app directory called app/Exports/UsersExport.php. <?php namespace App\Exports; use App\Models\User; use Maatwebsite\Excel\Concerns\FromCollection; class UsersExport implements

Scale up data imports with queue-based execution The time has come to put it all together. We’ve slowly built on in the previous articles and have increased our speed. With batch inserting we were able to insert a batch of 100 rows (even though you can pick any number). With chunk reading, we eliminated the memory problem of loading the entire excel sheet into memory and instead loaded a 100 rows worth of data (even though again we could have increased or decreased that number to whatever we wanted). But there’s still one more issue. What if the file is

Handle massive datasets with efficient chunk reading In our last article, we looked at Batch Inserting where we inserted a 100 rows at a time. Chunk reading deals with pulling a certain amount of data into memory. Without chunk reading, we pull the entire sheet into memory. That could be substantial if there is a lot of data inside the excel sheet. https://blog.devgenius.io/laravel-excel-p6-batch-imports-261c80e46448 How to use Chunk Reading? I hope that you’re seeing a trend appear: most things are pretty straightforward with Laravel-Excel. All we have to do is implement the WithChunkReading concern and use the chunkSize method. ?php namespace App\Imports; use App\Models\User; use

Efficiently process large-scale data with batch imports What we’ve done so far when importing our excel sheets into our database is create an import for each row: an actual insert query occurs each time. What if we had a 1000 rows? That’s right: 1000 insert queries would occur. Laravel does allow for batch inserts and Laravel-Excel accommodates that form of inserting. If you set a batch size of 100, that means that only 10 queries occur, not 1000. Batch inserting limits the number of queries done and increases the speed. The number of rows to insert in a single batch

Seamlessly process spreadsheet formulas with Laravel-Excel One last thing to note on importing excel sheets is that often formulas do not behave as you intended them to behave. If you start receiving errors, take a look at the excel sheet itself and figure out if there are any formulas hidden inside. https://blog.devgenius.io/laravel-excel-p4-importing-multiple-sheets-conditional-loading-d70db3ae1409 Let’s take a look at an example with one a formula that references data on the sheet that’s being imported. Formula on Import Sheet The excel sheet that we’ll be looking at has the following columns first_name last_name email password full_name The first four columns contain static data,

Streamline multi-sheet imports with advanced conditional loading There are a few quirks with Multiple Sheet importing that can be solved with Laravel Excel. If the creator changes the format, you’re out of luck of course, and will have to make the changes to your code. However, there are a couple of more things that may be beneficial to understand, like: creating specific imports but only using some of them and understanding how to handle formulas We’ll cover Conditional Sheet Loading in this article and handling formulas in the next one. https://blog.devgenius.io/laravel-excel-p3-importing-multiple-sheets-and-handling-unknown-defined-sheets-749dbc1ec089 Using Specific Importers You might have an excel sheet

Effortlessly handle multi-sheet imports in Laravel-Excel Ideally you receive the Excel sheet properly formatted and it’s a piece of cake when it comes to creating your import script, but when is that ever the case? You always have quirks and you have to devise methods to handle those. Luckily, Laravel-Excel has thought of quite a few of those quirks and provides great ways to handle them. This is a continuation of the Multiple Sheets Basics. https://blog.devgenius.io/laravel-excel-p2-importing-multiple-sheets-basics-2d20994770b Skipping Unknown Sheets When you receive an Excel workbook with multiple sheets, you may devise for import functionality for each sheet, but what happens

Master Multi-Sheet Imports with Laravel Excel Excel sheets will automatically be imported with Laravel-Excel. Sheets 1 through N will be handled the exact same way as sheet 0. We can specify how multiple sheets are handled, and we will in this article . Importing Multiple Sheets with the Same Format We’ll use our user mock data from the previous article and create a couple of excel sheets to store the user data. We now have user_data_1 and user_data_2 sheets. Each sheet stores the exact same type of data, both with headers (first_name, last_name, email, password) and 19 rows of user data. The MOCK_DATA.xlsx file is placed in our public directory. We’ll create our importer with our