Laravel

Rapid Application Development

w/ Modern PHP

Tea Time // @Highlights for Children

OOP

Object-Oriented Programming in PHP

PHP Classes \ Namespaces

  • Organize Code
  • Encapsulation
  • Magic
  • Inheritance
  • Interfaces / Traits
  • Abstract / Final
  • Composer / Autoload

Methods \ Properties \ Visiblity

MVC

Model - View - Controller

source: http://laravelbook.com/laravel-architecture/
{
	"name": "laravel/laravel",
	"description": "The Laravel Framework.",
	"keywords": ["framework", "laravel"],
	"license": "MIT",
	"type": "project",
	"require": {
		"laravel/framework": "5.0.*",
		"php-instagram-api/php-instagram-api": "dev-master",
		"pusher/pusher-php-server": "2.2.0"
	},
	"require-dev": {
		"phpunit/phpunit": "~4.0",
		"phpspec/phpspec": "~2.1"
	},
	"autoload": {
		"classmap": [
			"database"
		],
		"psr-4": {
			"App\\": "app/"
		}
	},
	"autoload-dev": {
		"classmap": [
			"tests/TestCase.php"
		]
	},
	"scripts": {
		"post-install-cmd": [
			"php artisan clear-compiled",
			"php artisan optimize"
		],
		"post-update-cmd": [
			"php artisan clear-compiled",
			"php artisan optimize"
		],
		"post-create-project-cmd": [
			"php -r \"copy('.env.example', '.env');\"",
			"php artisan key:generate"
		]
	},
	"config": {
		"preferred-install": "dist"
	}
}

Composer / Packagist.org

Routing
Middleware
Controllers

Request

Response

Views

Routing

<?php

Route::get('/', function()
{
    return 'Hello World';
});


Route::get('user/{id}', function($id)
{
    return 'User ' . $id;
});


Route::get('user/{id}/{name}', function($id, $name)
{
    return "User $id, for $name";
})
->where(['id' => '[0-9]+', 'name' => '[a-z]+']);

Eloquent ORM

ActiveRecord implementation.

Model layer in MVC.

Each object instance is tied to a row in DB.

Database migration system.

 

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('users', function(Blueprint $table)
		{
			$table->increments('id');
			$table->string('name');
			$table->string('email')->unique();
			$table->string('password', 60);
			$table->rememberToken();
			$table->timestamps();
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('users');
	}

}

Controllers

<?php

class HousesController extends BaseController {
 
 
	public function index()
	{
		$houses = House::all();
		
		return View::make('houses.index', compact('houses'));
	}
 
 
	public function create()
	{
		return View::make('houses.create');
	}
 
 
	public function show($id)
	{
		$house = House::find($id);
		
		return View::make('houses.show', compact('house'));
	}
}

.. back to Routes

<?php

Route::get( 'homes', ['uses' => 'HousesController@index'] );

Route::get( 'homes/create', ['uses' => 'HousesController@create'] );

Route::get( 'homes/{id}/view', ['uses' => 'HousesController@show'] );

Middleware

Great for handling processes that should occur during the life cycle of a request.

 

  • Pushing something to a queue.
  • Checking for Authentication
  • Maintenance Mode
  • Good for handling core additions
  • ... Handling of Request 

Blade Templates/Views

Let's you generate markup and views agnostic to any logic handling.

@extends('app')

@section('content')
<div class="container">
	<div class="row">
		<div class="col-md-10 col-md-offset-1">
			<div class="panel panel-default">
				<div class="panel-heading">Home</div>

				<div class="panel-body">
					Welcome {{ $user->name }}!
				</div>
			</div>
		</div>
	</div>
</div>
@endsection

...
<body>
    <header>
        <h1>Site Name</h1>
    </header>
    
    <article>
    	@yield('content')
    </article>

	<!-- Scripts -->
	<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
	<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/js/bootstrap.min.js"></script>
</body>
</html>

Livecoding

Thank you!

Tea Time: Laravel // Modern PHP

By Eric Katz

Tea Time: Laravel // Modern PHP

A presentation to go over modern PHP development practices, including introduction to object oriented PHP, Composer/Packagist.org and the rapid application development framework Laravel using LTS 5.1.

  • 710

More from Eric Katz