Adding Routes to the Navbar

In the next step we are going to change our Nabar so that it uses routes rather than hard coded urls. This will give us more flexibility in using SEO friendly urls but it will also allow our urls to work seamlessly after they have been deployed to a different server with a different base for the URL. i.e. Given that the domain name will be different it is likely that the initial part of the URL will look quite different. Routes protect us from changes in domain names.

Before we go forward we need to add some more functionality to tennis club application. To achieve this we need to return to the CLI and scaffold two more tables from our tennis club database. First we'll scaffold the "Court" table. To do this paste the following line into the CLI - make sure you are in the root folder of your project when you do this.

php artisan infyom:scaffold court --fromTable --tableName=court

Now scaffold the bookings table

php artisan infyom:scaffold booking --fromTable --tableName=booking

Now that Browse Read Edit Add and Delete functionality has been added there are a range of routes available. To see what routes are available type the following command into the CLI.

php artisan route:list

The results look something like this

In the last step we used our own parent view myapp.blade.php.

Next we want to modify the parent view in /resources/views/layouts/app.blade.php. The view that was generated by the scaffolder is a little bit complicated for our needs. Modify the section between the <body> </body> tags so that it looks like the following:

Now when you visit http://localhost:8000/members, you will see something like this. Try the links in the navbar to make sure they work.

Next, modify the navbar to include 3 more addtional routes from your navbar. Make sure is included in this. Click on your New Customer link in the navbar - does it have a different navbar then all your other screens? Why is this. Modify that view so that the navbar is the same as all the other screens.

Leave a Reply