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

Automating Nova Asset Publishing0:00

Well, friends, when you joined me, you were but the learner. Now, you are the master. I hope this course has given you all the tools you need to get started with Nova in your own apps. Before you hit production, there are a few minor steps we should take. Let me show you them briefly before we wrap everything up. Whenever Nova ships a new version, you should run php artisan nova:publish to make sure you've got the latest assets in your project. Now, obviously, you don't want to run that every time from the command line, so why don't we set up a Composer script to automate the process for us. Inside your composer.json file, you want to find the scripts node. And inside the scripts node, we have post-update command. So this will run any time Composer update is executed.

Registering Production Domains0:41

Inside your composer.json file, you want to find the scripts node. And inside the scripts node, we have post-update command. So this will run any time composer update is executed. So here we can say php to target the correct php version, php artisan nova:publish. And now every time we run composer update, after that has successfully completed, Nova will publish its assets automatically, saving us the task of having to remember. The next point we should touch on is the fact that our application is still unregistered. We need to register our app with Nova to make sure that our license is being used correctly. So on your license details page on nova.laravel.com, we can go to the production URL section and we want to add our production domains. So in this case, we'll add red.it. If you're using multi-tenancy or something involving wildcard subdomains, Nova also supports that.

Adding License Key in Env1:26

we want to add our production domains. So in this case, we'll add red.it. If you're using multi-tenancy or something involving wildcard subdomains, Nova also supports that. So we can say *.red.it in order to target any subdomain and make it valid inside the Nova admin panel. With our URLs added, go down to your license key and copy it, and then head back into your project and jump into the .env file. At the bottom of the .env file, we're going to add a new entry and that's nova_license_key. And you just want to paste in the license key that you've copied from nova.laravel.com. Now, obviously it's important that you do this in all of your environments. So if you're using something like Laravel Forge, be sure to go in and add your Nova license key in those environments.

Restricting Admin Panel Access2:08

important that you do this in all of your environments. So if you're using something like Laravel Forge, be sure to go in and add your Nova license key in those environments too. With our .env file updated, we can run php artisan nova:check-dash:license in order to make sure that we've entered the correct license key. And after executing that command, if we go back into our admin panel, note that the unregistered symbol is gone. We are now on a completely valid license of Nova. All right, one last thing to touch on is non-local access to our admin panel. In the case of the application we've been working on, users and customers are very separate things. So all users will have access to our admin panel, but you might have an application where your users are also your customers and only certain users should be allowed access to the admin.

All users will have access to our admin panel, but you might have an application where your users are also your customers and only certain users should be allowed access to the admin panel. So in order to illustrate this, I'm going to change my app environment to production because Nova by default will allow all users in local environments. And then I'm going to jump into the NovaServiceProvider and I'll head to the gate method in there. We have a permission defined called viewNova. And again, if you're in a non-local environment, this will take effect. So if I return false here, for example, and then we go back to our admin panel and refresh, yeah, now I have a 403. I can't access it. If I return back to the inArray method and I use luke@laracast.com, so I'll add this to the array here and refresh. Now I'm able to see things again. But let's go to a user that isn't me, maybe Rob Banks.

method and I use Luke at laracast.com, so I'll add this to the array here and refresh. Now I'm able to see things again. But let's go to a User that isn't me, maybe Rob Banks. And let's log out and log back in as Rob. So Rob at example.com and password. And yeah, 403, we can't get in. So you can use this gate method to very easily define which users should actually be able to have any access to the admin panel at all. Perhaps you have an admin flag on the user table. Maybe you actually hard code the email addresses like this, if it's always going to be the same set few, but however you do it, you probably don't want everybody having access to the admin panel. So make sure to configure your view NOVA permission before you ship to production. Well, with those few tasks out of the way, I'd say that's a wrap. You now know how to build an administration panel from scratch.

Course Wrap-Up4:23

view NOVA permission before you ship to production. Well, with those few tasks out of the way, I'd say that's a wrap. You now know how to build an administration panel from scratch using the power of Laravel NOVA and how NOVA allows you to very quickly iterate as your application grows and expands. I hope you've enjoyed watching the series as much as I've enjoyed creating it. And of course, if you have NOVA related questions, drop them in the comments. I'll do my best to answer them, but make sure to read the NOVA documentation as well for even more ideas and information on how you can get the most out of NOVA. And with that said, I'll see you soon.

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