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

Navigating to Classes0:00

Next up, very quickly, we should talk about how to get around, whether it's opening a file or going to a method or a symbol, or even triggering a specific phpstorm action. So let's get started. Now, of course, if I need to go to a particular file, how about the Kernel in this case, I could open the sidebar. On the Mac, that is Command-1. And yes, of course, I could manually open HTTP and visit my Kernel class in this way. And that's great. However, you may find that often, it's much quicker to instead close the sidebar. So I will hit Command-1 again.

So again, notice if I go back to Navigate, class on my machine is bound to Command-O. So Command-O, and let's type Kernel. And of course, for Laravel projects, there are two Kernel classes, one for your console entry point and one for your HTTP. So this is the one that I want. And yeah, you may find that, again, for your day-to-day workflow, this is a much quicker and snappier process. So if I close everything again with Command-W, if I know at the top of my head, I need to go to Kernel, Command-O, Kernel, and I'm there. Okay, but of course, instead, if I wanted to, I could visit Navigate File, and this

Switching Between Targets1:39

go to kernel, Command-O, kernel, and I'm there. Okay, but of course, instead, if I wanted to, I could visit Navigate File, and this is going to look not for the class name, but the name of the file. So notice here, it's matching the file name. And yeah, that's an option as well. But notice right here, we have a tab for classes. So I can switch or tab between classes or files or symbols, and notice if I hover over each one, it'll show me the keyboard shortcut. All right, so if I want to do files, that is Shift-Command-O, but classes is O. Or I could use the Tab key, and notice how I can tab between each of the options that

Quick Definition Preview4:38

Yes, please do. Apply the changes, and that's all it takes. So now I can hit Command-P to search anywhere in my project. All right, so let's just play around. Why don't we go into one of Laravel's controllers? How about the ParentController? And I can see that it uses two traits. Okay, I'd like to learn more about this ValidatesRequests trait. So I could go up to View, Quick Definition, and notice the keybinding, Option Space on a Mac.

Jumping to Definitions5:26

So how do I go back? Well, I could go back to Navigate, and then right up here at the top, we have Back. Go to your previous edit point. And once again, try to memorize these keybindings within Reason. All right, now we're back there. This time, I'm simply going to press Command, and then click on the file. And what's really great is this works for everything. It works for files, or classes, or even symbols and methods. So for example, if I browse this, it looks like Laravel calls a getValidationFactory method.

So for example, if I browse this, it looks like Laravel calls a getValidationFactory method. All right, I'd like to learn more. So once again, I will press Command and click on the method name. And there we go. It works. Okay, cool. So now we're getting a little bit more comfortable. We know that, of course, I can press Command W on the Mac to close a file, or Control W, probably on Windows.

We know that, of course, I can press Command W on the Mac to close a file, or Control W, probably on Windows. Or I can press Command P to search for any file in my system. So I could do index.php, but in a real project, there might be lots of files with that same name. So I can narrow it down by directory, or I could even use the first letter of the directory name, like p/index.php. And notice it still finds the same file, because it's leveraging fuzzy searching, which is really useful. Okay, so Command P, tab to get around, very useful.

So often, yeah, if you are, this is great for source typing, actually. If you're trying to learn something, all right, what's precognition? What's going on here? All right, we have this. And yeah, actually, on that note, notice that I Command clicked on this, but this is already the method definition. So there's nowhere to go. So instead, in those situations, it'll show me all of the usages, all of the places in the project where this method is called. And trust me, in your projects, you are going to reach for this all the time.

Using Recent Files8:24

Maybe a tiny bit slower, but it's negligible. Another option, though, is to browse to recent files that you have worked with. So I can go up to View, and yeah, right down here, Recent Files. And again, notice the key binding, Command E. And then we also have Shift Command E for Recent Locations. Both of these are really, really useful. So let's have a look. I will press Command E, and yeah, now I see a filtered list of only the files that I have recently visited or opened. And then further, if you're working on a new feature and you want to narrow that down to

recently visited or opened. And then further, if you're working on a new feature and you want to narrow that down to only the files that you have actually edited, you can check this here. Yeah, and it looks like in this case, maybe I've done something to User. I'm not sure. Let's try it. Let's go to Command P, kernel, and let's make a small little tweak. Maybe I will comment this out by pressing Command /. And yeah, now if I hit Command E, show edited files, that is now included in the list. And then also notice how the checkbox itself is also bound to Command E. So yeah, your

Filtering Tree Views10:18

whether it's your project tree here or even your settings menu here, all of them can be filtered and you just start typing. It's really easy. So for example, let's say I want to, I don't know, go to the routes directory here. I could select it manually or I could type the beginning of routes. Like this. And notice it instantly selects the first match. If I hit return, it opens the directory. And yeah, further, I could scroll down or from here I could type web and it instantly selects the file.

Well, I could just type in file watcher and it instantly takes me there. Or at least it takes me to all the places where file watchers are referenced. So for example, if I go into notifications, yeah, we can see that there. So anytime I need to configure something, yeah, trust me, I'm not manually opening and closing all of these directories. I'm searching for what I need. And yeah, it works everywhere in PHPStorm. If you see a tree, you can filter it. Okay. So the final thing I want to show you is if you often keep the sidebar closed, as I suggested,

And yeah, that's another way you can do it. And don't forget, if I bring that back up with command up, this is once again a tree view so I can filter this however I need to, which means I don't have to use the arrow keys if I don't want. If I quickly want to visit, I don't know, trim strings, yeah, in real life, I would type trim and it instantly filters it down and now I'm there. Pretty cool. And even better, while I have this floating menu, often you'll find when you're in a certain directory, like let's go back to controller, command P, controller, yeah, maybe I want to create a new controller within this directory.

Creating Files from Menu12:51

directory, like let's go back to controller, command P, controller, yeah, maybe I want to create a new controller within this directory. Well, one option is to hit command up and then command N for new directly within this folder. So let's create a new file and what do I want here? What kind of file? A PHP class or because I have the Laravel plugin installed, I can generate a controller directly from this floating menu. All right. What do we call it?

All right. What do we call it? How about the obligatory PostController or PostController? Yeah. We're off to the races. And yeah, to be honest, I think that's a really cool workflow actually. Command N to create a file in the current directory. Let's filter it down to Laravel. Let's do another controller. This can be, I don't know, maybe an invocable ContactController.

Let's do another controller. This can be, I don't know, maybe an InvocableContactController. So I will select singleAction and yeah, it works great. All right. So if you need to watch this video one more time, get these keyboard shortcuts ingrained in your muscle memory and when you're ready, let's move on to the next episode.

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