14 Quick Laravel Tips in 9 Minutes: May 2024

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys do you follow me on Twitter or anyone from Lille community on Twitter and yes by the way I still call it Twitter and will call it Twitter not X and Twitter is one of the best ways to get laral tips tricks news opinion and stuff like that and even if you do follow me on Twitter you probably don't see all of my tweets which I do tweet a lot around 10 tweets a day about laravel but not necessarily and in this video I want to kind of recap the most popular larl tips from my Twitter and someone else's Twitter as well that got the most engagement like the most likes or comments and generally was popular on various topics in Lille after this video in the comments below tell me if you like that format if you do then I will continue that probably by weekly or once a month because new tips are getting published almost every day on Twitter so in kind of Rapid Fire way let's go 15 or so laral tips in no particular order tip number one did you know that you can run PHP Artis on Migrate with-- pretend and it would show the SQL queries that would be executed without actually executing them yet so it's kind of like a rehearsal a dry run of your upcoming migrations tip number one tip number two comes from Ash Allen and it's his example of what pest architecture tests he uses in his application so to check that he didn't leave any DD and dumps in the code check to use strict types check commands to have handle methods and these are just a few examples of architectural tests if you want to find out more of them just read the pest documentation so this is tip number two or by the way if you have questions on any of those tips just shoot in the comments below and we can discuss together and maybe I will shoot a follow up on one of those topics so past architectural tests tip number two tip number three from myself did you know that you can create blade error pages with specifically HTTP status code and they will automatically be shown whenever that error happens for example a blade file resources views errors 500. blade. PHP and then if I abort with 500 that error would automatically appear so you can create such a page for all of your status codes or some particular ones like 403 blade. PHP and others tip number four also for myself is about blade so instead of doing if o user or if o check you can do the same thing with blade directives like o and the opposite of that is guest and this is one of those examples which strike me personally that those tweets that come almost directly from Lal documentations Pages get a lot of likes and retweets because a lot of people don't know them so personally it's almost painful to spend a day or two on some demo for more complicated subject and then get like 10 likes and then the next day just post some screenshot from the docks and get 200 likes but that's I guess how social media Works anyway that was tip number four tip number five even more classical ones but many people still don't know about 4 L's blade directive which makes the code shorter so I will zoom out so instead of having if and then else for empty you can use for else and empty with the same result tip number six also about Blade with five HTML attributes for conditions the ones that you can see on the screen and this is even more striking example of just putting two screenshots literally from the docs I didn't invent anything I just group them together in a tweet with link to the official docs and 200 likes amazing but I will zoom them in so basically in your button for example you can add at disabled with a condition and condition may depend on whatever in your project so it returns true or false and then that HTML input or HTML element becomes disabled based on true or false result similarly readon true or false required true or false also selected and checked for checkboxes and select dropdowns so that's tip number six tip number seven comes from Newton job and again another example of shorter code in laral using helpers here is zoom in so you can do if statement and abort if something goes wrong but also you can do gate allow if or even shorter gate authorize with a gate ability name this is tip number seven tip number eight from laravel backpack kind of official Twitter handle I use it quite a lot in EnV file I change mail driver to log and then whatever I send the email to test the application the email text with the code in both HTML and pl text can be found in this file storage logs laral log so the email Isn't actually sent so I don't need any driver like mailan or others I just check the email text in larl log tip number nine comes from anicat madom and this is about validation rules and the Order of those rules keep in mind that some of the validation rules trigger SQL queries to the database for example unique users would actually need to check if the user is unique so would launch SQL qu query and then if that query passes but Max validation fails it means that you launched one too many queries to the database so the advice and the tip here is to order the validation rules so anything triggering the database would come at the end a great tip in my opinion tip number 10 comes from myself five tips to go there will be 14 in total in this video If you have a blade view that you need to attach to a route you don't need to create a controller if you don't have any variables so instead of doing something like this you can just do route view so provide the URL and provide the blade file name so resources views home blade in this case you can also assign route name if you wish but you don't have to create a controller tip number 11 comes from Osama matter and it's about cloning the queries for example if you need to have kind of a base query repeated a few times with a different conditions with slightly different conditions you may do something like this I will Zoom that in so you create kind of the base query in the variable query but then you get one set of the results with one set of conditions and then another set with another condition and the main thing here is to clone the initial query so you can use the same base query multiple times in your other places in the code tip number 12 for myself and we're back to the topic of routing if you have multiple resource controllers you can group them together so there's route resource but there's also route resources plural which is just a personal preference I don't remember using it that much but sometimes it's beneficial it's cool and it's good to know the possibility of laravel syntax options tip number 13 comes from chat GPT recently I had a scenario where I needed to remember the opposite rule of required and I thought what was the rule name was it nullable was it optional was it something else and I asked Chad GPT in laral validation rules what is the opposite rule of required by the way way I don't remember which version was it was it four the newest one or 3.5 but I'm using free HPT version and what impressed me is that it gave back kind of a tutorial not just the answer of nullable but also examples so required with string but then also nullable with string which means that you can provide for example Max 500 symbols rule but that would be triggered only if the value is present because the value is actually nullable but if it does come through then the max rule would be automatically triggered so that's the first part of the tutorial and the second part is actually combining with other rules and also chpt mentioned an alternative sometimes validation rule which also can be used in some cases and finally tip number 14 comes from myself and again about routing did you know that you can do not only route group and not only route resource but also group the same controller methods if they are not in a resource way so there's no index store delete update destroy and stuff like that you can do a route controller group and then you don't need to repeat the controller name every time you just do the URL and the method URL and Method so the code becomes shorter and again the step kind of is from documentation but 250 likes on Twitter go figure but that was actually the reason for shooting this video so I thought if so many likes on Twitter probably people on YouTube would also appreciate such quick tips what do you think do you have any comments on any of those tips or on General format of this video let's discuss in the comments below that's it for this time and see you guys in other videos
Info
Channel: Laravel Daily
Views: 9,358
Rating: undefined out of 5
Keywords:
Id: goZOU0HPKwE
Channel Id: undefined
Length: 9min 9sec (549 seconds)
Published: Tue Jun 04 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.