4 Packages You Need in ANY Laravel Project

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys there are a lot of laravel packages out there and there are articles and questions like what packages do you need for laravel projects and it all depends on what your project does whether you work with excel exports for example or file uploads there are very popular packages for each of those areas but today i want to show you four packages that you will need no matter what so let's start with number one is laravel ide helper so laravel contains quite a lot of so-called magic under the hood with the facades and all the stuff that are not caught by id like php storm as a result you can see something like this so phpstorm underlines and doesn't really recognize as the main eloquent function task where so model where to avoid that there's a package called laravel id helper really old one 11 000 stars really popular and what it does it automatically generates php docs so your ide would understand a lot of stuff there are a few commands that you can run to generate some parts of the docs and in my example i have installed it already and i will show you how to generate the models so for that specific example for task where we need to run php artisan id helper models and then you get asked and this is a question that could be misunderstood do you want to overwrite the existing model files it's not that overwrite will change your code it would just add php dog blocks for every function i think or class somewhere in the file personally i prefer to not change the file itself but instead write to id helper models so in this case i choose no and then we have a new file in our php storm called underscore id helper models and here you have quite a lot of stuff generated for all your models in my case it's user model and task model that's all i have for this project and let's also run the main command of generate for laravel facades it will generate the main id helper which is this so a lot bigger file with a lot of stuff you can take a look but that doesn't really matter if we go back to the controller so that our where statement is not underlined anymore so this id helper package will help your ide like phpstorm underline only the actual errors and not the laravel magic package number two that i want to recommend comes from the same guy that created laravel id helper it's barry vanden hoevel i hope i pronounced the name correctly so he's a really old participant in larval community created one of those first packages for laravel including laravel debug bar and i use debug bar quite a lot in my own video so if you've seen that somewhere in my videos on the bottom where i measure performance or amount of queries so this is larval debug bar and the most often usage for that is the amount of queries that are run but there are much more things to see so it shows a lot of stuff for every request so let's try to install that both of those packages actually have dash dash dev1 installation because you need them only locally so install laravel bug bar and that's all you need to do you don't need to configure anything now if you load your page here's my page at the bottom you have queries models views and if you go to for example tasks the list of tasks there are three queries so laravel debug bar can help you see how many queries do you have and whether you have too many that's the most often usage but as i said there's a lot more stuff under the hood so you can check the documentation for all the features package number three that i want to recommend has similar purpose like laravel debug bar to detect the amount of queries that you run and you can detect that with debug bar as well so here i have an example tasks list with user name and in the blade file i have task username but i don't use eager loading so in the controller i adjust query tasks without mentioning the user which leads to the amount of queries being too many so for every task there is a query to the database to query its user so there are 18 queries and to avoid that you need to specify with here user so that's the solution and if we refresh there are only four queries if you didn't know about eager loading and n plus one query problem go to laravel documentation and search for eager loading but the package that i want to show you let's roll back for example if you don't have laravel debug bar or you forgot to take a look at it for example it's minimized for example and you just keep on working but there's a package that can visually show you the error in your face so to speak it's called laravel query detector and plus one query detector by marcel posiot from beyond code and here's how the result would look let's try it out we try query detector install it again it's dash dash dev because you need that only locally because you don't want to expose the amount of queries or name of your models on production it would be a security issue okay so we have installed that and there's nothing more to configure let's just refresh our page and as you can see it doesn't only show the query but shows what to change model task relation user you should add with user to eager load this relation so it shows the exact advice so you wouldn't even think what is wrong so i would suggest to install both laravel debug bar and query detector because n plus one queries is probably number one cause of bad performance in larval projects that i've seen in my experience with laravel and those packages will help you to avoid it finally the fourth package that i want to show you you probably will need it after your project is launched but i totally recommend laravel backup from spati it's probably the easiest way i know to back up your database or schedule the backup nightly or every hour or something so let's install that package from the documentation then what we need to configure by default it will backup the files as well but in my case in my experience it's mostly used for the database so this so let's configure that let's publish the config so this publish the config and then we have config backup file in our project so config backup and let's disable the files so empty array would be included in files and let's run php artisan backup run sending notification failed means probably tries to send an email or something that it is successful but generally it is successful let's see where that backup has been stored so storage app laravel from what i remember and zip file what's inside db dumps we have the sql with all our database including the data and you can schedule the backups automatically this is what i advise by default so whenever you release the project you immediately configure this so in schedule file in app console kernel so kernel of console this file in schedule you add the command backup run daily at whatever time you want and you forget about it so that's the least you can do probably you should configure that that backup of the database should be stored elsewhere on amazon s3 for example or whatever external server so in case your server goes down you will still have backup at least daily so these are four packages i recommend for any laravel project anything else that you would recommend shoot in the comments and let's discuss what more packages can we all use to make our lives better if you want more tips on laravel these packages or quick tips i suggest you follow me on twitter i already have 8 000 followers so join them and let's communicate there if you are on twitter and you can subscribe to my weekly newsletter which i send every thursday with random various laravel tips tricks my own articles and articles i find from the community over that week and see you guys in other videos
Info
Channel: Laravel Daily
Views: 36,009
Rating: undefined out of 5
Keywords:
Id: UORMYT8Fs9Y
Channel Id: undefined
Length: 8min 13sec (493 seconds)
Published: Tue Mar 09 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.