Let Laravel fetch your models automatically Now that we’re familiar with dependency injection, what else can we do with the concept? Can we “inject” our models, like the User model, into our route and then utilize model properties without instantiating the User model? How would we even do that? Don’t we need to first “find” the specific user before we can use the properties associated with that user? Believe it or not, Laravel has a way to get a user’s details without explicitly doing something like: User::find(24);. https://www.dinocajic.com/laravel-p50-routing-and-dependency-injection/ Implicit Binding We should understand that we do need to provide our model with an id at the very

Combine smart routing with seamless DI We’ve gone through a few dependency injection topics in the last couple of articles, but now we want to start getting more specific. We have finally entered a more advanced portion of Laravel and will start focusing on specific topics within specific areas of Laravel. The next few articles will deal with routing. In this article, we’ll focus on dependency injections in routes, which is really straightforward. https://www.dinocajic.com/laravel-p49-dependency-injection/ In your route you may type-hint any dependency into your callback signature. If you’re using controllers, the type hint will occur at the method level. use

Implement effective DI patterns for cleaner, testable Laravel code I hope that the last article made sense. Dependency Injection really is a simple concept. I feel like you should understand it in its entirety before you state that you know “Dependency Injection in Laravel.” Before we get into Dependency Injection again, you should understand Laravel’s service container. What is a service container in Laravel? It’s simply a tool that manages dependencies and it is this tool that actually performs the dependency injection. https://medium.com/geekculture/laravel-p48-dependency-injection-concept-high-level-php-concept-482e9f13d97b In the previous article, we looked at an extremely simple dependency injection example. <?php class Driver { private Car

Elevate your Laravel code with cleaner, modular dependencies You’re going to hear the term “dependency injection” many times throughout your Laravel career, so you might as well get acquainted with it. Before we get into Laravel, let’s look at Dependency Injection as a concept in PHP (or really any programming language). https://medium.com/geekculture/laravel-p47-final-touchups-cmp-5b2764c43565 We should know that we can pass objects as arguments to methods. We can also type hint with the inherited class, which is an overview of polymorphism in PHP. We can pass the object as an argument to the constructor. The constructor will then set the property inside

Give your Laravel project the perfect finishing touches It’s time to wrap this project up and move on to more advanced functionality in Laravel. Before we do, we need to add a couple of additional features to our Car Management Project, like deleting photos. This was a fun little project and in my opinion a little better than a traditional to-do list. https://medium.com/geekculture/laravel-p46-controller-destroy-cmp-6dab2b3da6aa Displaying All Images on the Show Page There is an issue with our show page. I’m sure you’ve caught that already. When we were just adding URL’s to other sites, it was easy to display the image.

Elevate your Laravel apps with Vue, Tailwind, and Vue Router Do you keep your backend completely separate from your front-end or do you try to integrate the Vue and Laravel structure into one project? I prefer the latter. It’s not as intuitive as it should be. I used to love the UI presets before, where you can select either React or Vue and move on. Although not terrible, we do need to set this up properly.   Installing Vue First, setup a new Laravel projects. I’m using Docker on a Mac, so my installation is pretty straightforward. curl -s “https://laravel.build/laravel-vue”

Simplify your Laravel setup with a seamless Docker environment on Windows We looked at setting up an existing project on Windows with Laravel, but we haven’t looked at setting up a new project. It is different and simpler than bringing in an existing project. https://blog.devgenius.io/setting-up-an-existing-laravel-application-100-with-docker-on-windows-870176679819 The first thing that you’ll need to do is make sure that your new PC is up-to-date. Next, you’ll need to update WSL. Open PowerShell and run the following command: wsl –update. Install Docker Can’t do much without Docker. Go to https://www.docker.com/ and download the latest version of Docker for Windows. Run through the prompts to install Docker.

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