Skip to content

Instantly share code, notes, and snippets.

View dwightwatson's full-sized avatar

Dwight Watson dwightwatson

View GitHub Profile
@dwightwatson
dwightwatson / Cache.php
Created January 20, 2016 23:17
A simple cache middleware for Laravel 5, which won't cache authenticated pages.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Cache\Repository;
class Cache
@dwightwatson
dwightwatson / NullingTrait.php
Created June 18, 2015 05:57
NullingTrait.php
<?php namespace App\Support;
trait NullingTrait
{
/**
* Boot the trait. Adds an observer class for nulling.
*
* @return void
*/
public static function bootNullingTrait()
@dwightwatson
dwightwatson / Homestead.js
Created January 19, 2015 03:46
Toggle Homestead Bookmarklet
javascript:(function() {
var host = window.location.hostname.substring(0, window.location.hostname.indexOf('.'));
var newHost = window.location.port == "8000" ? host + '.com' : host + '.app:8000';
window.location.href = 'http://' + newHost + window.location.pathname;
}());
@dwightwatson
dwightwatson / TestCase.php
Created September 9, 2014 02:22
Flush and reset Eloquent model events when testing.
<?php
class TestCase extends Illuminate\Foundation\Testing\TestCase {
/**
* Creates the appliation.
*
* @return \Symfony\Component\HttpKernel\HttpKernelInterface
*/
public function createApplication()
@dwightwatson
dwightwatson / RouteClass.php
Last active June 6, 2016 00:07
Get the controller name and action in Laravel 4 which can be used as a class in your HTML. This solution makes use of the parseCallback() and currentRouteAction() functions, which are handy if you want to devise your own version.
<?php
public function routeClass()
{
$routeArray = Str::parseCallback(Route::currentRouteAction(), null);
if (last($routeArray) != null) {
// Remove 'controller' from the controller name.
$controller = str_replace('Controller', '', class_basename(head($routeArray)));
@dwightwatson
dwightwatson / subnav.css
Created March 4, 2013 00:10 — forked from thomaspark/subnav.css
Subnavigation styles for Bootstrap 2
section {
padding-top: 60px;
}
.subnav {
margin-bottom: 60px;
width: 100%;
height: 36px;
background-color: #eeeeee; /* Old browsers */
background-repeat: repeat-x; /* Repeat the gradient */