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

Adding Package Discovery Metadata0:00

Next up is automatic package discovery. So if you've ever pulled in a Laravel package before, you're going to see the same steps over and over, regardless of the package. You require it, then you go to your config/app.php file, and you update your providers array, then you update an aliases array, if that happens to be relevant, and you're going to do this for every single package. And it gets kind of annoying, but now the package can automatically do this for you. So what we're going to do is update this very package to allow for that. I will switch to Sublime, and this is just a very simple Flash package that we built on Laracast. But anyways, if we come down to our composer.json file, we can add it right down here at the bottom. So for extra, this will be for any Laravel projects, and the service providers that I want to load will be, and let's just go back to Chrome. Here we go. So we'll grab that and paste it in.

Configuring Providers and Aliases0:42

So for extra, this will be for any Laravel projects, and the service providers that I want to load will be, and let's just go back to Chrome. Here we go. So we'll grab that and paste it in. And now further, if we want to set up any aliases for our facades, I happen to have one here, we could do this one. So it will be Laracast, Flash, Flash, like so. Finally, let's just escape these. And we're all set to go. So now in Laravel 5.5, it will recognize and read this composer.json file, and it will see, okay, we need to load this list of providers and this list of aliases. So now, the installer of your package no longer has to do that. So very quickly, let me do a git status. We're going to add that and say, add automatic package discovery, and push that up. So now, and push that up. So now, very quickly, let me publish a new release here, and we're all set. So now, let's try it out very quickly. Laravel new project, and it's not yet Laravel 5.5, so

Publishing Release and Testing1:38

and push that up. So now, very quickly, let me publish a new release here, and we're all set. So now, let's try it out very quickly. laravel new project, and it's not yet Laravel 5.5, so I'll pull in the dev version to grab that. Okay, let's cd in there, and then require it, Laracasts/Flash, and we can see it is grabbing the latest version. Finally, we can view this in the browser, and let's do this. Let's open up FlashServiceProvider, and right down here, we'll say var_dump(registering), just to show you that it is being triggered automatically. And there it is. So now, if we were to go to my routes file, I should be able to say flash(someMessage), and then let's just die(dump(session)). Okay, so we didn't get an error with that function, so we know everything's working correctly, and we can see that we did flash to the session. So if we look into it,

Verifying Flash Session Output2:29

in the session. Okay, so we didn't get an error with that function, so we know everything's working correctly, and we can see that we did flash to the session. So if we look into it, we do have a collection of items, and in this case, there's our message. And that's all there is to it. So vastly simplified automatic package discovery in Laravel 5.5.

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