New Model Attributes, Base64 Encoding, Collection Select & Array Take

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello la friends let's talk about what's new in the framework I got some pretty new cool features let me show [Music] you first we have two new methods for the string helper to base 64 and from base 64 and you guessed it already it's about base 64 encoding and decoding you can now do it fluently through the string helper thank you very much Mark next we got a new method on the array helper I'll show you I do have here an array of numbers one to six and what I already could do in level is make a collection out of this array collect numbers and then use the take method and yeah give me the three first items that's what this take method does or what we can also do is we can use minus three and then this will give us the last three items from this collection so this already worked and now we can do the same with the array helper level so this also takes a take method and then we provide our numbers and then the limit let's start with three again you can see the result is the same it's just an array and of course minus 3 works as well so you can use now the same method on the ray helper now I have two new PHP attributes you can use in your level applications they are not the first one we have in the framework but it's still is a pretty big deal so I have here my podcast model and what this model does is there is an observer for this podcast model let's take a look look at this podcast Observer so we're listening for some events and if they happen we do stuff and for the created event I'm just ring out here a lock message to see that a podcast was created and I have this atis on command to create a new podcast for me in this case and you can see here we get the message let's make this a little bit bigger but this worked already so this Observer was connected to our podcast model and this was being done here through the event service provider and here through the podcast observe method I've added my Observer so this is how this work but let's get rid of this and you can see now if we Crea a podcast we don't get this message because this Observer is not connected anymore but we now can connect it in a very new cool way by using an PHP attribute and the attribute is called observe by and now I can provide here my Observer class so similar as before podcast Observer class here and yeah if we create now uh podcast again you will see we get our log message again yes it works so now this is a new way how we can connect our model to an observer and I think this is very beautiful so my podcast model also has a global scope applied and this is being done through the boot method if we go down here you can see we are adding a clor scope and this one is called publish scope to only give me the podcasts which are published and if we take a look at our database here I'm doing this here right in PHP storm you can see we have three podcasts and only one of them is published so I have already prepared here a get Podcast arisan command which just locks me out the podcast which I have all of them and currently we only get this one which is published because our Global scope was working if we remove this run this again you can see we now get all of the podcast from our database because yeah the global scope is not being used here anymore but now there's a cooler way than using the boot method to do this we can also use a PHP attribute so again let's add another here this one is called scope buy and now we use our publish scope class and now if we run it again voila you can see this works now we only get our published podcasts back and this is now a very cool and more convenient way to do this and also this is done right inside the model itself which I really like thank you L for those new attributes and last there is new collection method which I'm 100% sure we all would have needed already a couple of times so I do have here a collection of arrays we have here team members from the level team Kristoff Joe and James email and chop and if I return this of course I get back just the collection but let's say we only want to get back now the name of all of them so what you could do is you could use something like the map method here on collection and then only return for every item here specific fields and in our case let's say only the name so this is how this could work let's run this yeah you can see we only have another name let's make this in Ray because because now it's a little bit easier to see here we only get back the name of all of those fields so this was working before but now we have a way better way to do this with the select method let's only provide the name here and well we have the same result pretty cool let's add another one let's say name and email and you can see now we have the email as well so this is now a way nicer way to select specific fields from a collection but only the ones that you want to see thank you you Craig wow pretty cool new stuff for you to use in your Lev projects have fun and please let me know in the comments which one you like the most see you soon [Music] bye
Info
Channel: Laravel
Views: 7,374
Rating: undefined out of 5
Keywords:
Id: jaSA0NlCMK0
Channel Id: undefined
Length: 5min 47sec (347 seconds)
Published: Thu Feb 15 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.