در حال بارگذاری ...

Introducing Str::password0:00

Alright, next up in Laravel 10, you have access to a new password helper method on the String class. Okay, so let's have a look. So in Visual Studio Code, where I'm using not, again, Laravel 10, but Laravel 9, if I switch over to the String class, Illuminate\Support\String, and I look for password, yeah, it's nowhere to be found. This is brand new to Laravel 10. Okay, so if I now switch back to my Laravel 10 project, and we return to that class, yeah, now you will find a password method. And this is pretty cool.

Explaining Options and Defaults0:31

now you will find a password method. And this is pretty cool. I like the way they implemented this. So we call a password method, we can provide a length, and then whether it includes letters or numbers or symbols or spaces can be overwritten. So yeah, by default, it includes letters, numbers, and symbols. So why don't we give this a shot? php artisan tinker. And yeah, if I want, I can use the full path here, Illuminate\Support\Str::password. And yeah, there we go.

Testing in Tinker0:55

And yeah, if I want, I can use the full path here, Illuminate\Support\Str password. And yeah, there we go. But of course, we can also use the str helper function. So I could do something like this. And there we go. Or maybe I want a password that's only 15 characters. It works. So yeah, you can totally imagine using this in situations where you generate an account for a User. You fire off an email, an account has been created for you.

Practical Use and Customization1:21

for a User. You fire off an email, an account has been created for you. Here is your temporary password, please sign in and update it to something you want, right? This is how you can achieve that now. And don't forget, if you want to override these, well, you don't have to manually pass in each one. You could, for example, disable numbers by simply saying, numbers is false. And there we go. You'll notice we have a password that will never include numbers. As you see there.

Str::password()

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟