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
Tag: Laravel
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
Mastering Form Validation in Laravel Controllers Adding data through the form is relatively straight forward. Making sure that the data is accurate is part of the process. That’s what this article is about. There are a couple of additional tweaks that need to occur such as inserting the penny amount, not the dollar amount, into the table. https://medium.com/geekculture/laravel-p42-controller-create-store-cmp-eabfcc50b234 Setters Just like we modified the attribute when we were retrieving it, we can modify the attribute when we’re setting it. The best place to do this, if it’s going to be consistent, will be in the model: PersonalCar. The three fields that
Controller Essentials: Understanding Laravel’s Create/Store Methods How do you insert a new record into the database? You can use tinker like we’ve been doing so far, but realistically we need to use a form. The user should see a blank form first and then click on the Submit button. The data should be sent over to another method in the controller that will help validate the data and send it to our PersonalCar model for insertion into the database. https://medium.com/geekculture/laravel-p41-controller-show-method-cmp-d503973018e7 Create The first thing that you need to see is a form. We have a route for it: it’s the route to the create method. Route::prefix(‘/personalcars’)->group(function() { Route::get(‘/create’,
Understanding the Show Method for Data Display The last article ended with us showing all of the resources in the personal_cars table. We need to be able to click on the resource and pull up the details for it. This is what the show method will do. It accepts a resource $id and then pulls the information from it. https://dinocajic.medium.com/laravel-p40-controller-index-method-cmp-f0c2b29861fc Adding the Link to Our Index View Before we can start working on the show method, we need to have a way to get to it. The route exists, so that’s one thing already cross off the list. Route::prefix(‘/personalcars’)->group(function() { // … Route::get(‘/{id}’, [PersonalCarController::class, ‘show’]); }); The user
Laravel Index Method: A Guide to Controller Essentials The controller architecture and the routes are setup and ready for us to start tackling. The first one on the list is index. We’re going to pull all of the data out of the table, put it into a view, and return it back to the user. https://medium.com/geekculture/laravel-p39-routes-and-controllers-high-level-setup-cmp-8b8cd8d0c46c The Route and the Controller Method We currently have the following code already created. Route::prefix(‘/personalcars’)->group(function() { Route::get(‘/’, [PersonalCarController::class, ‘index’]); // … }); <?php namespace App\Http\Controllers; use Illuminate\Http\Request; class PersonalCarController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response
Streamlining Laravel: Routes and Controllers High-Level Overview Now that our Model relationships are defined, we can start setting up the initial infrastructure for our routes and controllers. We’ll list out what kind of data will be sent, what we’re expecting, and then we’ll worry about creating views in the next article. https://medium.com/geekculture/laravel-p38-many-to-many-relationship-cmp-bd8847de9114 Brainstorming I’ve purposefully not created any of this beforehand. I’m writing this code as it seems natural to me. What I want to do is brainstorm on what we need to create next. We know that we have the following models: PersonalCarBrand PersonalCarModel PersonalCar Image The question is,