---
title: Controllers
---

# Controllers

<div class="documentation__toc"></div>

## Introduction

### Base Controllers

The `base` controller is extended by both `public` and `admin` controllers and provides some basic functionality built in.

We recommend you extend the `public` or `admin` controllers below. However you can extend `Anomaly\Streams\Platform\Http\Controller\BaseController` with your own controller and do as you like.

#### Default Properties

```php
$this->container   = app();
$this->request     = app('Illuminate\Http\Request');
$this->redirect    = app('Illuminate\Routing\Redirector');
$this->view        = app('Illuminate\Contracts\View\Factory');
$this->asset       = app('Anomaly\Streams\Platform\Asset\Asset');
$this->events      = app('Illuminate\Contracts\Events\Dispatcher');
$this->template    = app('Anomaly\Streams\Platform\View\ViewTemplate');
$this->messages    = app('Anomaly\Streams\Platform\Message\MessageBag');
$this->response    = app('Illuminate\Contracts\Routing\ResponseFactory');
$this->url         = app('Anomaly\Streams\Platform\Routing\UrlGenerator');
$this->breadcrumbs = app('Anomaly\Streams\Platform\Ui\Breadcrumb\BreadcrumbCollection');

$this->route = $this->request->route();
```

#### Default Middleware

```php
$this->middleware(Anomaly\Streams\Platform\Http\Middleware\VerifyCsrfToken::class);

$this->middleware(Anomaly\Streams\Platform\Http\Middleware\PoweredBy::class);

$this->middleware(Anomaly\Streams\Platform\Http\Middleware\ForceSsl::class);
$this->middleware(Anomaly\Streams\Platform\Http\Middleware\PrefixDomain::class);

$this->middleware(Anomaly\Streams\Platform\Http\Middleware\SetLocale::class);
$this->middleware(Anomaly\Streams\Platform\Http\Middleware\CheckLocale::class);
$this->middleware(Anomaly\Streams\Platform\Http\Middleware\ApplicationReady::class);

$this->middleware(Anomaly\Streams\Platform\Http\Middleware\HttpCache::class);
```


### Public Controllers

A general `public` controller is provided to be extended by your own for use with publicly accessible routes.

You can get started by extending `Anomaly\Streams\Platform\Http\Controller\PublicController` with your own controller.

#### Default Middleware

The `public` controller only adds a single but important middleware for general public access controllers:

```php
$this->middleware('Anomaly\Streams\Platform\Http\Middleware\CheckForMaintenanceMode');
```


### Admin Controllers

A general `admin` controller is provided to be extended by your own for use with `control panel` routes.

You can get started by extending `Anomaly\Streams\Platform\Http\Controller\AdminController` with your own controller.

#### Default Middleware

The `admin` controller only adds a single but important middleware for general control panel controllers:

```php
$this->middleware('auth');
```


### API Controllers

A general `resource` controller is provided to be extended by your own for use with `API` routes.

You can get started by extending `Anomaly\Streams\Platform\Http\Controller\ResourceController` with your own controller.

#### Default Middleware

The `resource` controller disables the `VerifyCsrfToken` middleware by default.


## Rendering Views 

Use the `view` helper or property to `return` views from a controller.

```php
<?php namespace Anomaly\ExampleModule\Http\Controller;

use Anomaly\Streams\Platform\Http\Controller\AdminController;

class ExampleController extends AdminController
{
    public function example()
    {
        return view('anomaly.module.example::pages/example');
    }
}
```

### Passing View Data

You can `method inject` classes like a [repository](../entries/repositories) to pass `entries` along to use in the view. 

```php
<?php namespace Anomaly\ExampleModule\Http\Controller;

use Anomaly\Streams\Platform\Http\Controller\AdminController;
use Anomaly\ExampleModule\Example\ExampleRepository;

class ExampleController extends AdminController
{
    public function examples(ExampleRepository $examples)
    {
        return view('anomaly.module.example::pages/examples', [
            'entries' => $examples->all()
        ]);
    }
}
```

> Data passed to views is automatically [decorated](../templating/presenters).
