Playing
11. Composer dev command

Transcript

00:00
New Laravel installations now come with a Composer script which run a few commands to just get you up and running while you're developing locally. Let's go ahead and take a look. Now I've just freshly installed this Laravel app.
00:13
The first thing I'm going to do is make sure we've installed all our npm dependencies with npm i or npm install. And let's just head, before we run this command, let's head over to composer.json and have a look. So you can see now that under the script section, just here, within here, we've now got this dev command. Let's take a look at what this does. So it goes ahead and uses npx concurrently to run concurrently.
00:37
So it will run all of these commands together. And let's take a look at what this actually does run. So it runs php artisan serve. So this is a local command which goes ahead and creates a PHP server for your Laravel application. If we take a look, I'm currently using Laravel herd, but we'll see this in action in a second when we open this up in our browser. It also goes ahead and runs our queue listener. So if we are queuing anything, this will now run this and listen for us.
01:05
And it will go ahead and also run php artisan pale. Pale is a application from Laravel which tails your logs in the console. So you'll be able to see anything you log out within your console. And it also runs the standard npm run dev, which we are used to. It gives you these all names. We don't really need to worry about that. That's just for the benefit of npx concurrently. And you can see that a color is associated with each of these commands as well.
01:31
So you can identify them within your terminal when you run this. So that's what's happening when we run composer run dev. Let's go ahead and check this out. So we'll run composer run dev, hit enter on that and just wait. So there we go. You can see that we've got a color associated for each of these. Let's just scroll up. We've got dev in here for white and we are going ahead and processing or running our queue.
01:58
We are enabling logs with pale and we're running a server here and we're running npm run dev with white, which is a different color. So, for example, within our application now, what we can do is when we go ahead and log something out. So let's just log hay out here and we head over to the browser and give that a refresh. Let me come back over. You can see pale is now logging this out to our terminal.
02:18
And again, it is given the color that was specified when we used npx concurrently. So now we have a much more convenient way to get started with local development by just running one command. This isn't going to be for everyone, but it does really help rather than having to have multiple tabs open to run your queues, run npm run dev and run pale if you do use that to keep an eye on your logs.
02:44
So another thing that we explained earlier is this runs a PHP web server that you'll be able to just get set up with Laravel instantly if you're not using something like Laravel herd. So if I open this in the browser, you can see this does exactly the same thing. There's nothing here at the moment, but this is now serving our Laravel application. And we can see that by the log that's just been logged out as well. So a really simple command.
03:05
Of course, another benefit to this is you can add to this if you want to or you can modify it. So, for example, you could come over here and if you wanted to modify the color, you could. If you wanted to get rid of any of these commands, you could as well. So, for example, you didn't want to use pale. You could just get rid of this.
03:23
The composer.json file is yours, so you can do with this what you want. And of course, you can add other commands in here as well if you need something else to run. So feel free to modify this, get rid of stuff, tweak it. It is now a much more convenient way to run some common actions rather than having to have multiple tabs open in one go.
26 episodes2 hrs 34 mins

Overview

Need to know what’s new in Laravel as it happens? Every episode of this course is dedicated to covering the most interesting and useful Laravel additions in detail, so you’re ready to start using them in your applications.

Check back often, and stay completely up-to-date with Laravel.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!