Laravel Modules Demo: Make Your Project Modular

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys what if you're working on a laravel project so big or it becomes so big that you want to split that into modules so for example you have like in my case like 20 controllers then it grows to 50. it's some kind of a crm for example or a bigger project that has logical modules for example client management like task management expense management settings and whatever and you want each model to be controlled by its own namespace folders and kind of be a mini laravel project in itself how to do that it's all in this video so i decided to create this experiment demo project based on our generator of quickadminpanel.com i've generated this project with contact management module expense management module and task management module and also quick admin panel comes by default with user management so there are four big modules and this is how it looks in our quick admin panel com so it generated a lot of crowds by just installing the tasks and calendar expense management and contact management module and by default it is just a set of crudes which are all in one folder as controllers like this how to split that and i asked a colleague nerius to use a package called laravel modules it's a well-known package quite an old one from nicholas with art it's kind of like a standard package in laravel community to split the application into modules so i asked my colleague to create a separate branch on the repository which is public by the way on github to transform existing controllers and existing structure into the module structure and let's see how it looks like before we dive into the code the introduction about the package itself laravel modules generates you something like this so there's a folder modules and each time you run an artisan command php artisan make module or module make your module name it creates a subfolder with kind of like a mini laravel project in itself so you have the database migrations the controllers here the providers the resources and the goal here kind of sub goal is that if you have a team of developers some developer may go into for example blog module and work only on that without touching any other modules so you have kind of application within an application so this is a structure how to run module make by default and to install that package is actually pretty easy you install the package you publish the config and then you ought to load the modules folder not much more you need to do actually and then create a new module is just as simple as module make and then inside of those folders you work with the structure but let's now take a look at our demo project what is actually changing from default level structure into modular one so here's the pull request with changing the structure into modules with those three modules so task management expense management and contact management and it's all 190 files changed but it's actually much fewer than that because there's something like git keep here in the pull request so some files that are not interested and let's take a look at a particular commit for example transforming the contact management module and what we have here in the route in the main routes web we delete everything that is related to our module which was like company controller and contact controller and instead we need to fill our contact management routes web so routes web actually appears in our modules contact management and we paste those here and the namespace is taken care of by default in route service provider of that contact management so each module has its own service provider which has route service provider and that route service provider defines the namespace like this that comes by default when you do module make so basically you need to move your routes from global routes web to the module routes web and in similar fashion you just move other files for example if we go to migrations it's just removing the file from global database migrations and moving that into modules contact management database migrations so two migrations moved also you move the models this way but for this package the standard thing is to call that things entities and not models but it's basically the same thing and then one by one you basically move all the files into its own structure inside of the modules folder there are of course things that you need to change manually so for example in the controllers you need to change namespaces from app to module from using the request from your app http you use the modules contact management http requests like this also you move the views from resources views into resources views of the module and then you refer to them like this so module name so you have some kind of a prefix then added similar here in the example so some more manual changes to make another small example if you remove the form request file into the modules you need to change the namespaces so you get the idea you can almost run a multi-replace in your ide or write a bash script to replace the namespaces where needed it would make even faster so if you have bigger project with like 100 controllers or something it makes sense to even automate that but even if done manually it's a pretty easy thing to do so if your project has grown up and you think to divide that into the modules this is the package to help you laravel modules by nicholas woodard and if you want to generate admin panel like this one it's not modular in the sense of subfolders for modules but it totally works you can manage your users or install more modules so this is the list of our modules including stuff like multi-tenancy csv import internal messages and others so you can support this channel by purchasing quick admin panel com and generate the admin panel for you that's it for this time see you guys in other videos
Info
Channel: Laravel Daily
Views: 12,052
Rating: undefined out of 5
Keywords:
Id: RVApkrYMcAg
Channel Id: undefined
Length: 5min 53sec (353 seconds)
Published: Wed Sep 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.