Skip to content

Instantly share code, notes, and snippets.

View coreymcmahon's full-sized avatar

Corey McMahon coreymcmahon

View GitHub Profile
<?php namespace App\Models;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Database\Eloquent\Model;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
@coreymcmahon
coreymcmahon / BaseController.php
Created January 27, 2015 11:43
BaseController.php - A Pattern for Reusable Resource Controllers in Laravel 4.2 http://slashnode.com/reusable-resource-controllers/
<?php
/** ...etc */
/**
* @param array $fields
* @return array
*/
protected function data($fields = array())
{
$rules = $this->validator->getRules();
@coreymcmahon
coreymcmahon / ExampleController.php
Last active August 29, 2015 14:14
ExampleController.php - A Pattern for Reusable Resource Controllers in Laravel 4.2 http://slashnode.com/reusable-resource-controllers/
<?php namespace App\Controllers;
class ExampleResourceController
{
protected $repo;
protected $model;
protected $validator;
public function __construct(Repository $repo, Model $model, Validator $validator)
{
@coreymcmahon
coreymcmahon / index.blade.php
Last active August 29, 2015 14:14
admin/products/index.php - A Pattern for Reusable Resource Controllers in Laravel 4.2 http://slashnode.com/reusable-resource-controllers/
@extends('layouts.master')
@section('title', 'Products')
@section('content')
<h2>Products</h2>
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
@coreymcmahon
coreymcmahon / ProductsController.php
Created January 27, 2015 10:40
ProductsController.php - A Pattern for Reusable Resource Controllers in Laravel 4.2 http://slashnode.com/reusable-resource-controllers/
<?php namespace App\Controllers\Admin;
use App\Controllers\BaseResourceController;
use App\Models\Products;
use App\Repositories\Products;
use App\Validators\Product as ProductValidator;
class ProductsController extends BaseResourceController
{
@coreymcmahon
coreymcmahon / routes.php
Created January 27, 2015 10:38
routes.php - A Pattern for Reusable Resource Controllers in Laravel 4.2 http://slashnode.com/reusable-resource-controllers/
<?php
Route::group(['prefix' => 'admin', 'before' => 'auth.admin', 'namespace' => 'App\Controllers\Admin'], function ($router) {
$router->resource('products', 'ProductsController');
});
@coreymcmahon
coreymcmahon / BaseResourceController.php
Created January 27, 2015 10:35
BaseResourceController.php - A Pattern for Reusable Resource Controllers in Laravel 4.2 http://slashnode.com/reusable-resource-controllers/
<?php namespace App\Controllers;
abstract class BaseResourceController extends BaseController
{
protected $repo;
protected $model;
protected $validator;
public function index()
{
@coreymcmahon
coreymcmahon / ConcurrencyExample.php
Last active August 29, 2015 14:10
The 12 Factor PHP App: Concurrency example using Queues - http://slashnode.com/the-12-factor-php-app-part-2/
<?php
// this code is run by the "web" process
namespace App\Services;
class UserCreator
{
public function create($data)
{
// ... etc
@coreymcmahon
coreymcmahon / ReactDemo.php
Created November 22, 2014 09:04
The 12 Factor App: Port binding example with ReactPHP - http://slashnode.com/the-12-factor-php-app-part-2/
<?php
include __DIR__.'/vendor/autoload.php';
$app = function ($request, $response) {
$body = "" . time();
$response->writeHead(200, ['Content-Type' => 'text/plain']);
$response->end($body);
};
@coreymcmahon
coreymcmahon / Post.php
Created August 29, 2014 09:21
Using the Repository Pattern - example 3 - http://www.slashnode.com/why-use-repository-pattern/
<?php
class Post extends Model
{
public static function getRecent()
{ /* … etc …*/ }
}