Skip to content

Instantly share code, notes, and snippets.

View kirkbushell's full-sized avatar

Kirk Bushell kirkbushell

  • Tectonic Digital
  • Sydney
View GitHub Profile
@kirkbushell
kirkbushell / Post.php
Created August 27, 2023 12:31
Updated syntax for supporting caches in Eloquence
<?php
use Eloquence\Behaviours\CountCache\CountedBy;
use Eloquence\Behaviours\CountCache\HasCounts;
use Illuminate\Database\Eloquent\Model;
class Post extends Model {
use HasCounts;
#[CountedBy]
<?php
'cloud' => env('FILESYSTEM_CLOUD', 'do'),
..
'do' => [
'driver' => 's3',
'key' => env('DO_ACCESS_KEY_ID'),
'secret' => env('DO_SECRET_ACCESS_KEY'),
@kirkbushell
kirkbushell / File1.php
Created March 11, 2016 14:43
The question is - does Player upgrade buildings, or does a service do this, or does the building upgrade itself and deduct costs from Player?
<?php
class Player
{
public function upgrade(Building $building)
{
if (!$this->canAfford($building)) {
throw new DamnImBroke;
}
$this->deduct($building->upgradeCosts());
@kirkbushell
kirkbushell / BuildingId.php
Last active March 9, 2016 23:53
Weirdness in PHPSpec?
<?php
namespace IronSteel\Construction;
use IronSteel\Library\Uuid;
class BuildingId extends Uuid
{
}
@kirkbushell
kirkbushell / Interceptor.js
Created January 7, 2016 22:41
Handling JWT, Vue JS and token refreshes
import Unauthorised from './Unauthorised'
export default function() {
return {
response: function(response) {
switch (response.status) {
case 401: return Unauthorised.handle();
}
return response;
// parent
<template>
<header class="content-header">
<h1 class="h2 first">Track workout</h1>
</header>
<div>
<ul class="exercises">
<li class="exercise" v-for="exercise in exercises" track-by="$index" transition="item">
<div class="col-sm-6 col-xs-12 selector">
<button class="btn btn-default" v-on:click="selectExercise()">Select exercise</button>
@kirkbushell
kirkbushell / Handler.php
Created August 10, 2015 14:43
Custom exception handler
<?php
namespace AwardForce\Library\Exceptions;
use AwardForce\Library\Http\FormInputOutdatedException;
use AwardForce\Library\Http\Messaging;
use AwardForce\Library\Traits\Respondable;
use AwardForce\Modules\Accounts\AccountNotFoundException;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Response;
@kirkbushell
kirkbushell / XSSProtection.php
Last active November 5, 2021 06:08
Laravel 5 XSS protection middleware
class XSSProtection
{
/**
* The following method loops through all request input and strips out all tags from
* the request. This to ensure that users are unable to set ANY HTML within the form
* submissions, but also cleans up input.
*
* @param Request $request
* @param callable $next
* @return mixed
<?php namespace Modules\User\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateUserRequest extends FormRequest
{
public function rules()
{
return [
'email' => "required|email|unique:users,email,{$this->user->id}",
@kirkbushell
kirkbushell / Kernel.php
Last active August 29, 2015 14:16
Avoid Laravel 5 middleware in tests
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use Illuminate\Pipeline\Pipeline;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* @var array
*/