Skip to content

SQL Buddy v2.0: Adding a Route

Gilbert Pellegrom edited this page May 6, 2016 · 2 revisions

Step 1

Open up bootstrap/routes.php and add a new route:

$router->add('/example', 'ExampleController::index');

If you need to do anything more complex you can access the underlying RouteCollection instance by doing:

$router->routes()->add(...);

For more info see the Symfony routing docs.

Step 2

Create a new controller in src/Controllers with the same name you added in your route. It should look something like:

<?php

namespace SQLBuddy\Controllers;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class ExampleController extends BaseController
{
    public function index()
    {
        return $this->view('example');
    }
}

If you need it you can type hint Request $request in the method parameters. Controller methods should return a Symfony Response.

For convenience a view($template, $data = []) method exists to return a Blade template (in the resources/views folder).

Clone this wiki locally