From the course: Laravel Essential Training

Unlock the full course today

Join today to access over 25,100 courses taught by industry experts.

Register resource routes

Register resource routes - Laravel Tutorial

From the course: Laravel Essential Training

Register resource routes

Before we start adding functionality to these controller actions, we need routes to call each of these actions. So go to the routes file, web.php. Here, we first need a get route to show all of the notes that points to our NoteController's index action, index. And then we need a route to show the form that will point to the create action. We need a route to store it, and we need a route to update, and so on. Instead of writing all these multiple route declarations, you can register a single resource route that points to the resource controller like so. We use the resource method and we give the URL like notes. This is the common URL. And then we point it to the entire controller. This single line will create all the resource routes required for us. Let's verify using the command php artisan route:list. Notice all of these routes were created for us. And look at the names of each of these routes: notes.index, notes.store, notes.create, and so on. So it uses notes and then the suffix…

Contents