YouTubevideo· Sep 19, 2024· 10:40· 3,700 views on YouTube
React at a moment you like. The best moments light up here.
the updates and new features for the framework that were announced at LaRon are finally released in the latest version of larel which means I get to talk to you about two of my favorite ones and then a couple bonus ones that I really like that were announced by Taylor so if you haven't checked out this thread by Taylor be sure to check it out as well as a couple of videos from the Lille official Channel talking about what is new with laravel now all of these or at least most of these we announced at laracon and here's the two
that I really like one that I am going to use quite a bit and another that I haven't used yet but I'm excited to try the first is the defer function now there's a whole blog post I'm going to link in the description of other people who are walking through exactly what this does but here's what happens instead of returning the response in a
nutshell instead of returning the response directly in this defer function it's going to turn the spawns then spit up a new PHP process in the background to run anything else in this function now this isn't meant to replace cues this is just saying hey if you have something that usually takes a little bit 3 seconds 5 Seconds 10 seconds maybe
maybe you're hitting a external API or maybe you're sending an email or maybe dispatching a couple of cues maybe you don't want to do it right on the request you want to show the user that this actually has happened or is in the process of happening that's where defer can come in where in this example that Taylor's showing you defer sending off a
new report or a new queue or new job what have you what I will probably use it mostly for is maybe sending individual emails that's probably a thing that I am looking forward to using I really am looking forward to using it in demo specifically because there's a lot to go into setting up AQ and especially if you're just teaching someone hey this should be pushed to the background isn't something that should happen in the process of the request but
this is a way to kind of show the right way of doing it without having to set it all up so that's what I'm looking forward to using it for but mostly I think for dispatching jobs anything that takes longer than one or two seconds and I need to show the user hey here's a response immediately but I still want other things to run then defer is perfect again this should not replace Q
jobs I'll give it a little demo of how I'm using it in a particular application this is just not a real world application but defer is not meant to be used in replace of Cu jobs defer is to be used for those things that you just need to move that to the background and not necessarily have to process it right away because defer has no failure safe
like fail safety you can't defer something and then if it failed run it again like you can with CU jobs where you can retry jobs everything like that defer is just saying saying I want something to happen just not immediately and so I think this is going to be incredibly helpful for people to feel like their PHP applications are fast because it uses uh PHP fpm I believe or
fast CGI under the hood I know that those are similar in a lot of ways but what's happening is it's just spitting up a new process to run the thing without having to run the thing in that immediate response one other thing that was not announced at Lon but I like because it kind of has a really cool story of how this came to be this wi helper function I released a video a
week or so ago about running background jobs with multiple steps and in it I talked about having to have this if block where I say if this particular method or this particular status then wire pull and I was saying kind of in the comments that it' be nice if I didn't have to do that like wi pull if or something and then smarter people than me Josh Henley and Dan Matthews kind of came up with the idea of what would happen if there was a at win directive which eventually turned into this win helper function which came to
be in the latest release of lville so it's cool how open source like Lille has this ability to have conversations with people like Dan Matthews and Josh Hanley where now you have the opportunity to change the things you like about the things and the tools that you use and while I didn't make this change I am incredibly grateful for people like Josh Hanley and Dan Matthews who proposed this change and made this change happen where we have this win helper I'll show that in a little bit next is this info method so instead of
having this like log facade helper it's just this Global info method to be able to say hey I just want to log something I have been using this a little bit more if I'm just whooping up some demos usually I might use like Ray from spoty for some more detailed logs but instead of like DD I just might use log and then I use PHP Artisan pale or it just gets sent to my herd logs and then the last
two honorable mentions would be the temporary URL on local file system which is incredibly helpful I love this within my S3 systems but now you can do it locally and then lastly concurrency facade to be able to run multiple things at the same time and you can also use it in the same context of deferred so we can say I want to run all these things but now defer them to the background that's awesome right now I can run all of these in this case jobs or cued jobs
or maybe even batch cued jobs that I now want to concurrently run but defer them to the background so concurrency is kind of just like an additional helper with the defer method to make those things really happen in sync to be able to say I want two things to happen at once and concurrency is great to make that happen
so I'm really excited for that particular feature I haven't created any demo kind of demoing that or even used it in any of my projects yet but I know that that is going to be extremely helpful especially when you know two things two jobs need to happen at once and maybe like you're setting up a whole new project for someone within your application and five things need to happen instead of having to do those literally now we can do those concurrently and even defer to the background maybe we use the the win
method to wire pull for each of those until it has been set or that status has been set I'm extremely excited for all of these let's jump into a demo so here is the fur and win method as well as the log method just for fun in this volt component I have two states state of message and is pulling is true now
previously in my other video I had to do some weird stuff of like uh at if is pulling and then I do a bunch of other stuff to say I want to you know run this with a wire pull or maybe I can split it out and do the at at if in line which is fine but it it gets a little messy it gets a little cumbersome and now this win method has makes this a lot easier uh double bang win is pulling double bang is necessary uh for the wire
pull function the method that wire pull needs so that way it doesn't escape those variables so when is pulling then we're going to wire pull the check cache method the Deferred message has been set in the in this case the cache has been set which is being set in the defer function up here then we're just going to turn is pulling to false so what you'll see happen again I'm just using kind of the cache to make this happen this would probably be the same thing as if you I was running a background job and changing some uh ene
in the database or maybe I was changing just a column of the database that it was is finished to true and then I'm constantly just checking the database here instead of checking the cache so this is based on a real world method but this particular instance is probably not
something you would be doing in your application but there's a bunch of times when you need to do something in the background and maybe this is just deferring to run a q job in the background but it has to do a couple things in the interim maybe send an email and then run a c job this defer function is just saying for 5 seconds something is going to happen in the background but I don't want to let the user know that it's happening I don't want them to wait on that process that browser request for 5 seconds but we're
going to put that in the cache which will then check the cach and that should change and change is pulling is Def false now here's where the defer method is going to come into handy we can defer all of this logging the message and that should happen immediately because we deferred it in this case immediately after the first request has been sent but then this sleep is going to happen before it puts it in the cash but this message is going to change before this
finishes because this is being deferred see what I'm saying so if we take a look we press defer what we should say is this message change before the cache gets updated so press it message change hi there folks and we'll also see then that the Deferred message change so the cach has been set 5 seconds later and we see here in our debug that deferring this message has been set so one more time we'll refresh defer log set this is a deferred
message there we go there is so much potential for a lot of these new features within larel and one of my favorite thing regardless of me being on the laravel team or not because I don't have a hand in any of this stuff within the framework one of my favorite things about laravel and the community and just open source in general is things like this or the wi helper can happen they
can happen by just people having conversations by people trying new things by people learning new things by making silly little videos like this and then we just learn new stuff like this most of this was not in the framework a year and a half ago including volt literally this whole page would not exist if people didn't start iterating
over things things and learning new things and building new things and I'm grateful for every single thing on this page including V because it's my favorite yeah so keep learning keep creating