Title Text

Folder Structure

The Good Old Days

Pretty much everything was in the app folder.

The New World Order

The app folder is now the project's PSR-4 root.

There are three top level namespaces - Console, Http, and Providers.

Dot Env

.env

An environment file in your project root directory

 

Access the environment variables with the getenv() function

APP_ENV=local
APP_KEY=tv8kVT*&vktV&*k78tv78TVK&*T
DB_USERNAME=root
DB_PASSWORD=supersecurepassword
$username = getenv('DB_USERNAME');

Contracts & Facades

What Is a Facade?

A shortcut for accessing a shared service.


$app = app();

$config = $app['config'];

$default = $config->get('database.default');

$default = Config::get('database.default');

Dependancy Injection

The "DI Container" can examine a class, and "inject" its  dependancies.

 

use Bitbucket\TerribleApi;

class IssuesController {

    public function __construct( TerribleApi $api )
    {
        $this->api = $api;
    }

    public function showIssues()
    {
        return View::make('issues')
            ->with( 'issues', $this->api->issues() );
    }

}

$app->bind('Bitbucket\TerribleApi', function()
{
    return new TerribleApi( $username, $password );
});

What is the alternative?

<?php namespace App\Http\Controllers\Auth;

use Illuminate\Contracts\Auth\Guard;
use Illuminate\Routing\Controller;
use Illuminate\Routing\Redirector;

class AuthController extends Controller {

	/**
	 * @Post('get/me/away/from/here', as = "logout")
	 */
	public function logout( Guard $auth, Redirector $redirect )
	{
		$auth->logout();

		return $redirect->route('home');
	}

}
Made with Slides.com