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
Category: Web Development
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
Effortless Data Handling with Laravel Excel In this article, we’ll be discussing the laravel-excel package that can be found on laravel-excel.com. It’s a task that most developers face. How do you import an excel sheet or CSV file into a database? What if you have a ton of vendors and each of them provides you with a specific format? That’s where data importers shine. The Manual Approach to Importing Excel Files It is always an option. You know what the database structure looks like. You know exactly which columns you have inside of your tables, which data type is necessary, and as long
Simplifying Data Removal with Laravel’s Controller Destroy Method We’re down to our last method: destroy. The destroy method will, you guessed it, remove a resource from the database. This is the simplest of the bunch. We simply need to create a link, delete a resource and return the user to the index page. https://medium.com/geekculture/laravel-p45-controller-edit-update-cmp-b16b5b77aaaa Route The route is already created. We did this a few articles ago. Route::prefix(‘/personalcars’)->group(function() { Route::delete(‘/{id}’, [PersonalCarController::class, ‘destroy’]); }); We simply need to send a delete request to our personalcars/{id} route. Creating a delete request Before we can destroy a resource, we need to be able to get there. How do you send a delete request to
How to Use Laravel’s Controller Edit/Update Methods Effectively We have just a couple of more articles to go before we wrap up this project in its entirety. We’ll move on to more advanced topics after that. In this article, we’ll tackle how to edit a record. We’ll need to display a form with all of our form fields already populated for a particular record and then when we click update, we actually have to update our record. https://medium.com/geekculture/laravel-p44-form-single-image-upload-cmp-53c519dcd97d Our Routes The routes are already created. The edit and update routes will call the edit and update methods respectively. The edit method pulls the record from the
Implementing Single Image Upload in Forms The image upload. Instantly throws fear into the beginner developer. I’m not sure where the fear comes from but it’s one thing that developers fear. Laravel makes the process incredibly simple so we don’t have to stress about file uploads in general. https://medium.com/geekculture/laravel-p43-controller-form-validation-cmp-a365b8256066 This is a continuation from our article discussing forms. Our form needs to have a file upload button, which it does (create.blade.php). <div class=”flex flex-col mb-4″> <div class=”mb-8″> <label class=”mb-2 font-bold text-lg text-gray-900 block” for=”file”>Select Image</label> <input type=”file” name=”file” id=”file” class=”mb-2 text-lg text-gray-900″ /> </div> </div> We simply need to process
