تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Improve Migration Foreign Keys0:00

And then something else that I found which we can write better is inside our videos migration. Here we're defining a relationship to the course and we can also do this with a better method called foreignId for and then we don't have to define a string for the field, but we can provide the class itself like this. And isn't this now way better to read? We are creating a foreign ID for a relationship for a course. I like this way better than before. And again, just to be sure, let's run all of our tests. Okay, we see now one of them is failing. Let's see which one is that. It gives back successful response for course details page here. I think here we forgot to add that we need releasedCourse as well. Yeah, here we go. Just one more time, running all tests. Yeah, 11 tests and

Reorganize Test Files0:53

page here. I think here we forgot to add that we need released course as well. Yeah, here we go. Just one more time, running all tests. Yeah, 11 tests and they are all passing. Okay, the only thing left here is about our file structure. So if we go to our tests, we can see that we have here a directory for models, but then we have some page tests here which are not inside a directory and I'd like to have them in a directory as well. So let's create a new one here. So all tests that are about a specific page I'd like to have in the pages directory. And since those tests are no classes with no namespace, everything should already work without checking if we need to change a namespace. Yeah, so that's one of the advantages when we use with the past testing framework. And similar to this, I

Reorganize Page Views1:38

without checking if we need to change a namespace. Yeah, so that's one of the advantages when we use with the past testing framework. And similar to this, I think also for our views here. Yeah, here we can also create a new directory for pages. And let's grab those two and put them into the new pages directory. And by the way, you can also already get rid of the welcome.blade.php file, which we don't need. And I assume now that this change will fail some of our tests because we have to define the new location for a view file, which wasn't done automatically. So let's go to our controller here, PageHome, the other controller for the course details, it's the same. And I think this already should be it. Let's see, unknown view file. So why is this not working? Oh yeah, it's called pages, right? Right.

Optimize Video Count Loading2:24

details, it's the same. And I think this already should be it. Let's see, unknown view file. So why is this not working? Oh yeah, it's called pages, right? Right. Okay, let's run the tests. And yeah, they are good now. So we've made sure that we now have dedicated directories for our pages here, inside our resources, but also tests that belong to specific pages are now also inside this pages directory. Oh, just one more thing here on my list, which we haven't tackled yet. So let's get to our controller here. So here we are passing the course to our view file. And then inside our view file, we are making use of the videos method. It looks like a property, but in effect, it's a method which we are calling to get all the videos, and then we make a count. So this is not very efficient because the only

property, but in effect, it's a method which we are calling to get all the videos, and then we make a count. So this is not very efficient because the only thing we need here is the count because we don't do anything with the data of each of those videos. So this means what we can do here is for better performance. Let's go back to our controller here for our Course. So what I can do here is I can call a method called loadCount on our Course to load a specific count for a specific relationship. In our case, it's for the videos relationship. And now we can change how we get the count for our videos. So instead of getting all of the videos, I can now use videosCount, which is now a new property, which we get back through the loadCount method, which we have used inside our controller. And I

Rename Route Names4:02

videos, I can now use videosCount, which is now a new property, which we get back through the loadCount method, which we have used inside our controller. And I can show you everything is still working, but now we don't have all the video data inside our view, which we actually don't need. Now the really last thing that I want to do is insert our route file. So we have changed the location of our view files to a patients directory. And I also want to use this for the names of my routes. Now, of course, we should see some failing tests here. Yeah, quite a lot of them. So let's change this by going to our PageHomeTest first. And every time we've been using this, let's change this to pages.home like this. Here we go. So I think this file should be good now. Yes, it does. And the other test should be

Wrap Up Refactoring4:49

we've been using this, let's change this to pages at home like this. Here we go. So I think this file should be good now. Yes, it does. And the other test should be PageResponseTest. Yeah. Here again, we're going to add pages here. Yes. Well, and this should be fine now for this test here. And then last, we also have our PageCourseDetailsTest. And yeah, here as well. We need to change this in a few tests here. Let's change this to pages. I think now with this change, everything should be good. Yes, it does. And now we are really finished refactoring this first feature. And you probably have noticed since we were mostly focusing on getting things done in the first step of our TDD approach, we now had a few things here and there that we could change to improve our code. But yeah, now we had

getting things done in the first step of our TDD approach, we now had a few things here and there that we could change to improve our code. But yeah, now we had some more time and just could focus only on how to make our code better, which I really like about refactoring inside a TDD approach.

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