1 00:00:00,057 --> 00:00:05,510 Welcome back, in this section, we'll cover the differences between controllers and 2 00:00:05,510 --> 00:00:08,613 resource controllers used for CRUD operations. 3 00:00:08,613 --> 00:00:13,404 While this course doesn't go into full explanation of CRUD functionality, 4 00:00:13,404 --> 00:00:18,046 it's crucial to understand how both work, and more importantly, how and 5 00:00:18,046 --> 00:00:19,162 when to use them. 6 00:00:19,162 --> 00:00:24,120 Laravel assigns common CRUD routes to resource controllers with a single line 7 00:00:24,120 --> 00:00:24,728 of code. 8 00:00:24,728 --> 00:00:29,993 For example, creating a controller that handles all HTTP requests for 9 00:00:29,993 --> 00:00:32,811 courses stored by your application. 10 00:00:32,811 --> 00:00:34,390 As I mentioned earlier, 11 00:00:34,390 --> 00:00:39,440 you can use an Artisan command to make a resource controller with CRUD built in. 12 00:00:39,440 --> 00:00:43,379 The optional -r flag is the only difference between the two 13 00:00:43,379 --> 00:00:47,570 Artisan commands for controllers and resource controllers. 14 00:00:47,570 --> 00:00:51,607 Let's create our first resource controller, so we can take a look at 15 00:00:51,607 --> 00:00:55,228 the differences between a controller that returns a route and 16 00:00:55,228 --> 00:01:00,049 a resource controller, by using the main controller Artisan command like this. 17 00:01:08,090 --> 00:01:12,130 Once you've created the resource controller, 18 00:01:12,130 --> 00:01:16,663 navigate to the App\Http\Controllers directory, 19 00:01:16,663 --> 00:01:20,418 and open the ExampleController.php file. 20 00:01:20,418 --> 00:01:24,950 You'll notice that both controllers are very much alike, with the exception that 21 00:01:24,950 --> 00:01:29,429 the resource controllers have all of the CRUD functionality pre-built for you. 22 00:01:29,429 --> 00:01:33,696 With one command, you get resource controllers out of the box, 23 00:01:33,696 --> 00:01:34,888 how cool is that? 24 00:01:34,888 --> 00:01:38,046 We won't use resource controllers in this course, 25 00:01:38,046 --> 00:01:41,563 but it's useful to know how Laravel makes CRUD operations 26 00:01:41,563 --> 00:01:45,240 rather intuitive to implement using the optional -r flag. 27 00:01:45,240 --> 00:01:48,284 Without the -r flag, it's just a controller, 28 00:01:48,284 --> 00:01:51,633 not a resource controller with CRUD functionality. 29 00:01:51,633 --> 00:01:56,401 Resource controllers make building CRUD functionality a snap, and 30 00:01:56,401 --> 00:01:59,941 the Artisan CLI makes it even easier to implement. 31 00:01:59,941 --> 00:02:05,297 We can also use the middleware method to attach middleware to controller actions. 32 00:02:05,297 --> 00:02:09,244 To learn more about middleware, check the teacher's notes below. 33 00:02:09,244 --> 00:02:14,044 In the next session, we are going to build all the views we need for our Laravel app. 34 00:02:14,044 --> 00:02:17,731 Then we'll test our routes, closures, and controllers, 35 00:02:17,731 --> 00:02:21,650 to see how they display the views in the browser, see you there.