5. Updating the Routes in web.php

Before I begin adding methods to the PostController.php file, I will create all of the necessary routes in the web.php file, located in the routes directory. These routes will determine the methods in the PostController where users will be directed to.

It should be noted that some routes were automatically added by the authentication scaffolding. The GET request for '/' returns the welcome view (welcome.blade.php), which is a landing page, was added by the scaffolding. The GET request for '/home' returns the home view (home.blade.php - i.e., a dashboard) for logged-in users, again added by the scaffolding. Finally, the 'Auth::routes();' line was also added by the scaffolding.

Below is a screen capture of the web.php routes file.

It should be noted that precedence does matter in the routes file. For example, the GET request for '/posts/create' must come before the wildcard GET request for '/posts/{post}'. Otherwise, the word 'create' would be considered as the wildcard to be interpreted. To explain the syntax, the use of '[PostController::class, 'index']' indicates the controller to be used, as well as the function within that class which will be run. In this case, the index() function would be invoked.

Comments