Creating a basic controller
Model-View-Controller (MVC) patterns are very popular in PHP frameworks. In this recipe, we'll create a simple controller that extends another base controller.
Getting ready
To start, we just need a standard Laravel installation.
How to do it...
To complete this recipe, follow these steps:
In the
app/controllers
directory, create a file namedUsersController.php
and type the following code in to it:<?php class UsersController extends BaseController { public function actionIndex() { return "This is a User Index page"; } public function actionAbout() { return "This is a User About page"; } }
Then, in the
routes.php
file, add the following lines:Route::get('users', 'UsersController@actionIndex'); Route::get('users/about', 'UsersController@actionAbout');
Test the controller by going to
http://your-server/users
andhttp://your-server/users/about
, whereyour-server
is the URL to your app.
How it works...
In our User controller (and pretty much in any...