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

Finding a Bug0:00

Let me show you how to contribute to Laravel from scratch. So of course, the first step is to find a feature to implement or a bug to fix. Let's do the latter. So I have a fresh copy of Laravel 5.5 installed, which at the time of this recording isn't yet available. However, that doesn't mean we still can't contribute to it. Now, one of the things that Laravel 5 offers is this new preset command. So it gives you a way to quickly scaffold some front-end files and assets for Bootstrap or Vue or React or strip them entirely. So let's take a look at that.

or React or strip them entirely. So let's take a look at that. Right now, with a fresh install, this is what you get out of the box. Just some hints as to how you might want to structure your app. We pull in a Vue components directory. We have some sass to get us started. You've probably seen this before. But now if I were to run php artisan preset none, that basically says, no, we're not using Vue or Bootstrap. Just strip all of that away.

Vue or Bootstrap. Just strip all of that away. So let's run that. And if I run git status, you'll see that it deletes a bunch of directories and files. So if I switch back, now app.scss is empty. App.js is very simplified. Our package.json no longer has any references to jQuery or Bootstrap or anything like that. However, if we go into this Bootstrap file, you can see that at the moment it still requires jQuery and Bootstrap sass. So that means currently this will error out as soon as you compile everything down because

Forking and Cloning Framework1:44

I'm going to go to Safari. I'm at github.com/Laravel/framework. And I'm going to fork a copy of this. So now I own this version. Next, I will clone it down to my system. git clone. And then finally, if I switch over to framework, you can see it's set to the 5.4 branch. But now in our case, we want to submit a bug fix to master. And the basic rule is if you're submitting a fix to a release of Laravel that's not yet out, then you will always use master.

Locating Preset Code2:06

And the basic rule is if you're submitting a fix to a release of Laravel that's not yet out, then you will always use master. On the other hand, if you're submitting a patch to 5.3, then you would submit to that branch. OK? All right, so let's git checkout master with that in mind and open this in phpStorm. Now, in the source directory, you can see all of the various Laravel components. So what we want to do is go into foundation, console, and then we want the various presets. So let me show you this first. We're going to go into preset command.

So let me show you this first. We're going to go into php artisan preset. So this is the command that's responsible for php artisan preset. Now, you'll see if we scroll down, it basically takes the argument you give it. So in this case, if we do none, it tries to call a none method. So in this case, it defers to a none class and it calls a static method. So let's go to that, install, and this is what it does when we trigger that command. OK, so we can see that, yes, it deletes a bunch of directories that are no longer required. However, it also updates the bootstrapping. So let's take a look at that.

Updating None Preset Stub3:07

However, it also updates the bootstrapping. So let's take a look at that. And we can see that it opens app.scss and replaces it with nothing. So it basically deletes the contents of the file. And then also it copies a app.js stub to your resources directory. But in our case, we saw that we really need to copy a bootstrap.js stub as well. So let's update this and say copy bootstrap.js to bootstrap. OK, let's open up the sidebar. And here's our none stubs. So we can see that's what ultimately we want this file to look like.

And here's our none stubs. So we can see that's what ultimately we want this file to look like. We're going to create another one here for bootstrap.js. And now what I'm going to do is just find the original code we want. So let's go to Laravel, into the Laravel project, and then let's see, resources, assets, js, bootstrap. So this is what it produces normally. So we're going to grab that and just replace it because we've decided this no longer is appropriate. So I will delete that entirely.

appropriate. So I will delete that entirely. OK, so now that should mostly do it. If we come back, we're now going to copy this modified stub to your resources directory, and that should fix the bug. So let's come back and run git status. We can see our changes. There are no tests for this particular feature, which is fine. So I will add that to the staging area. There we go.

Committing and Pushing Fix4:27

So I will add that to the staging area. There we go. And we will commit with a simple message that describes what this commit will do once merged. So we could say update bootstrap.stub. OK, so now with that committed, I can push that up. All right, and if we switch back and go to our commits directory, switch over to the master branch, sure enough, we can see our change. That looks great. But now before we submit this PR, let's just do a quick sanity check to make sure that it does, in fact, work.

Testing Fix via Composer4:56

But now before we submit this PR, let's just do a quick sanity check to make sure that it does, in fact, work. So what I'm going to do is switch back to our Laravel 5.5 toy project here, and I'm going to pull it in. We can do that like this. In composer.json, I'm going to add the repositories option here. And this is where I can specify any custom repositories that I want Composer to know about. Now, what do we want to add here? Let me just show you the quick documentation on Composer's website.

Now, what do we want to add here? Let me just show you the quick documentation on Composer's website. Loading a package from a VCS repository. The most common use case is when you want to maintain your own fork of a third-party provider. Okay, so we're going to add a type of VCS and then specify a URL to where our local copy is. So then when you require it in, it will use your local version rather than the default. So let's paste that in. And then we want JeffreyWay/framework.

So let's paste that in. And then we want JeffreyWay/laravel-framework. Okay, so let's give this a shot. I'm going to run composer update jeffreyway/laravel-framework. Okay, and that should do it. So now, for example, if we take a look at that None class and scroll down, you'll see that it does reflect our personal copy. So here's what we'll do. We're going to try it again from scratch. In fact, I have a little alias called gnaw that I use that simply defers to this.

We're going to try it again from scratch. In fact, I have a little alias called gnaw that I use that simply defers to this. So reset everything and then clean any unstaged files. Okay, so now we can start from scratch just like we did at the beginning of the video. All right, php artisan preset none. And now that should update everything. Our sass is empty. But further, our bootstrap.js file no longer has references to jQuery or bootstrap-sass, which is exactly what we want. So I think we're all set here now.

Submitting the Pull Request6:37

which is exactly what we want. So I think we're all set here now. We're ready to PR this. Our master branch is one commit ahead of Laravel master. So I will submit a PR. And if we scroll down, we can see all of the changes that I made here. Now you'll see that by default, the title will take the shape of your commit message. Let's say update none preset bootstrap stub. Now for the description, so many people leave this blank. Personally, for my own projects, I really hate it when people do that.

Now I always recommend that you take a look at your PR. Now in this case, we are taking our master branch. Now we could have created a feature branch on our fork. In this case, it's just such a quick fix. There's no real reason to, but in some cases, and in a lot of teams, you would do that for every single fix you make. And then we're going to PR that to the master branch. Okay, create the pull request. So now in real time, Thursday at 1035, we've added a new pull request to update the none preset bootstrap stub.

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