Skip to content

Instantly share code, notes, and snippets.

@thepsion5
thepsion5 / AclMiddleware.php
Last active September 16, 2015 20:29
Possible ACL Middleware Implementation for Laravel 5.1.11+
<?php
use AppName\Posts\Post;
use Illuminate\Http\Request;
class GenericAclMiddleware
{
private $entityClasses = [
'post' => Post::class
];
@thepsion5
thepsion5 / gist:f35d09ed9b5c8393671a
Last active August 29, 2015 14:24
Laravel Self-Validating Request Example
<?php
namespace MyAppName\Http\Requests\Members;
use Illuminate\Contracts\Validation\Validator;
use InternalPackage\Laravel\Traits\SessionFlashNotifierTrait;
use MyAppName\Http\Requests\Request;
class ImportMembersRequest extends Request
{
use SessionFlashNotifierTrait;
@thepsion5
thepsion5 / ModuleAServiceProvider.php
Last active July 18, 2018 11:40
Simple Module Concept for Laravel 5
<?php
namespace App\Providers;
use Illuminate\Support\ModuleServiceProvider;
class FooModuleServiceProvider extends ModuleServiceProvider
{
protected $moduleName = 'Foo Module';
protected $moduleNamespaces = ['App\FooModule'];
<?php
class FacebookUrlHelper
{
private $graphApiUrl;
private $fbHostname;
public function __construct($graphApiUrl = 'http://graph.facebook.com', $fbHostname = 'facebook.com')
{
@thepsion5
thepsion5 / gist:19ae573f6939ff40992f
Created January 30, 2015 18:49
Shell Script to run migrations and database seeders on a Laravel 4 application and dump the resulting DB contents to a SQL file
#!/bin/bash
#Retrieves an environment variable from the correct environment file
#Based on the specified environment
#Example: getEnvVariable local DB_USER VARIABLE
#Will attempt to retrieve the DB_USER array value from the file at .env.local.php
#And then store the result in VARIABLE
getEnvVariable(){
local RESULT=$3
local LOCAL_RESULT=$(php -r '
$file = getcwd() . "/.env." . trim($argv[1]) . ".php";
@thepsion5
thepsion5 / ServiceContainer.php
Created December 9, 2014 01:17
Simple Service Container Example
<?php
class ServiceContainer
{
protected $services = [];
protected function setCallable($serviceKey, Callable $service)
{
$this->services[$serviceKey] = $service;
return $this;
@thepsion5
thepsion5 / .env.template.php
Created October 8, 2014 22:20
Example of a .env.php template, so developers using their own credentials know what's required
<?php
//Template for all required environment variables
return array(
'DB_USER' => '',
'DB_PASS' => '',
'DB_DATABASE' => '',
'BUGSNAG_KEY' => '',
'NEW_RELIC_APPNAME' => ''
);
@thepsion5
thepsion5 / BaseController.php
Last active February 29, 2020 15:27
Example of using A Laravel Controller to automatically handle validation exceptions and auth failures
<?php
class BaseController extends Controller
{
public function callAction($method, $params)
{
$ajax = Request::isAjax();
try {
return parent::callAction($method, $params);
@thepsion5
thepsion5 / ContactFormHandler.php
Created June 20, 2014 15:59
Simple contact form example
<?php
class ContactFormHandler
{
public function __construct(ContactFormTemplate $template, ContactFormValidator $validator, ContactFormMailer $mailer)
{
$this->template = $template;
$this->validator = $validator;
$this->mailer = $mailer;
}
@thepsion5
thepsion5 / EloquentFooRepository.php
Created May 2, 2014 15:09
Example implementation of a Eloquent-based repository that provides a fluent interface for sorting and pagination without exposing the underlying model API.
<?php
class EloquenFooRepository
{
/**
* The base eloquent model
* @var Eloquent
*/
protected $model;