InsertOrIgnoreUsing, Adding Multiple Global Scopes & Unlink Storage

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello lar friends we just came back from the brilliant lar conu conference this week but this doesn't mean we forgot about you we got some new features for [Music] you first there is a new method for adding Global Scopes so we're here inside my user class and inside the boot method here I'm applying two clobal Scopes one for all the ri users and one for for active uses and now we have a new method which we can utilize which is ADD Global Scopes here and what this receives is an array so let's just provide our two classes here as an array our verified scope class and the active scope here let's reformat this and yeah now there is a more convenient way if you want to add more Global Scopes than just one and using one method thank you eliser next an update for linking your storage folder we're here in the terminal of my level application and what we can do in level is using phpn storage link to create a Sim link for our storage directory so let's take a look at our public folder by ls- lpu and you can see here at the bottom we have our storage Sim link which is cool but sometimes you want to get rid of this you don't need this anymore and now you can also do this with an artisan command called storage unlink and of course you guess that it just deletes our Sim link let's check again here on the public and you can see now this is gone thank you Mikel and last we have a new insert method with the wonderful name insert or ignore using love it already we're here inside my insert users command which I have in level signatures insert users and we're just inserting a couple users into the database just Tim and chess from the level team we're using the insert method and if if we run this command here you can see this should just work yes it does and inside our database I can check this here in ppor as well you can see we have our two users Tim and chess so this is working as expected but what if we're going to run this now again of course this is going to fail because our email should be unique and let's see it here yeah we don't want a duplicated user so Tim is already failing here okay so what happens now if if we maybe want to add other entries here or we still have other entries that we want to get into the database like for example let's put in here oo Cho name is Cho email is Cho at laral yes here we go so we want CH to be in the database as well but of course if we run this command again it will already fail for Tim so what we can do here is use a different method than insert it's insert or ignore and this was already working um in L for quite some time so now this command is not failing and if we check the database you can see we still don't have duplicates but we also have now Cho in the database welcome Cho okay so this is nice and working as expected and next to the insert or ignore there's another method which we already had before which is let's use this now on a different table which is insert using so what this does it inser erts users to this new backup user table which I had from another um table but first we want to Define we only want to use the email field and yeah the other database where we want to get this from is from the table users and here we also specify that we only want to get the email field which is yeah by the way it's email let's also fix this fix this at the beginning and yeah that's all we just want to use all those users in this other table this is working let's check this table yes now we also have all three users in this table as well but we have the same issue if we run this again this is failing again for the same issue because of our duplicate violation here so this means what we can do and this is finally what's new here we can now use insert or ignore using this new method which combines both of them and now we can run this command as much as we want to and now this is not failing but we also don't have any duplicates thank you Trevor let me know which new feature you like the most in the comments and see you the next time bye
Info
Channel: Laravel
Views: 4,086
Rating: undefined out of 5
Keywords:
Id: hNuvsJOGEqY
Channel Id: undefined
Length: 4min 45sec (285 seconds)
Published: Thu Feb 08 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.