Skip to content

Instantly share code, notes, and snippets.

@dwightwatson
dwightwatson / Cache.php
Created Jan 20, 2016
A simple cache middleware for Laravel 5, which won't cache authenticated pages.
View Cache.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Cache\Repository;
class Cache
View 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 Jan 19, 2015
Toggle Homestead Bookmarklet
View Homestead.js
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 Sep 9, 2014
Flush and reset Eloquent model events when testing.
View TestCase.php
<?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 Jun 6, 2016
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.
View RouteClass.php
<?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 Mar 4, 2013 — forked from thomaspark/subnav.css
Subnavigation styles for Bootstrap 2
View subnav.css
section {
padding-top: 60px;
}
.subnav {
margin-bottom: 60px;
width: 100%;
height: 36px;
background-color: #eeeeee; /* Old browsers */
background-repeat: repeat-x; /* Repeat the gradient */
You can’t perform that action at this time.