Skip to content

Instantly share code, notes, and snippets.

View danb-humaan's full-sized avatar

Dan Barrett danb-humaan

  • Humaan
  • Perth, Australia
View GitHub Profile
@danb-humaan
danb-humaan / UuidModel.php
Created December 3, 2015 10:07
Trait for implementing UUIDs in Laravel models
<?php
namespace App\Traits;
use Rhumsaa\Uuid\Uuid;
use Illuminate\Database\Eloquent\ModelNotFoundException;
/**
* Trait UuidModel
* @package App\Traits
<?php
namespace App\Traits;
use Rhumsaa\Uuid\Uuid;
use Illuminate\Database\Eloquent\ModelNotFoundException;
/**
* Trait UuidModel
* @package App\Traits
/**
* Binds creating/saving events to create UUIDs (and also prevent them from being overwritten).
*
* @return void
*/
public static function bootUuidModel()
{
static::creating(function ($model) {
// Don't let people provide their own UUIDs, we will generate a proper one.
$model->uuid = Uuid::uuid4()->toString();
/**
* Scope a query to only include models matching the supplied UUID.
* Returns the model by default, or supply a second flag `false` to get the Query Builder instance.
*
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*
* @param \Illuminate\Database\Schema\Builder $query The Query Builder instance.
* @param string $uuid The UUID of the model.
* @param bool|true $first Returns the model by default, or set to `false` to chain for query builder.
* @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder
/**
* Scope a query to only include models matching the supplied ID or UUID.
* Returns the model by default, or supply a second flag `false` to get the Query Builder instance.
*
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*
* @param \Illuminate\Database\Schema\Builder $query The Query Builder instance.
* @param string $uuid The UUID of the model.
* @param bool|true $first Returns the model by default, or set to `false` to chain for query builder.
* @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder
module.exports = {
entry: getEntrySources(['./src/js/entry.js']),
output: {
publicPath: 'http://localhost:8080/',
filename: 'build/bundle.js'
},
devtool: 'eval',
module: {
preLoaders: [
{
{
"name": "humaan-demo-webpack-react-app",
"version": "1.0.0",
"description": "A basic environment for writing React apps in ES6 and built using webpack",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"webpack-server": "webpack-dev-server --hot --progress --colors",
"web-server": "http-server -p 3000 .",
"start": "npm run webpack-server & npm run web-server"
"images": {
"low_resolution": {
"url": "https://scontent.cdninstagram.com/hphotos-xfp1/t51.2885-15/s320x320/e35/12338585_1668903330056644_140182574_n.jpg",
"width": 320,
"height": 320
},
"thumbnail": {
"url": "https://scontent.cdninstagram.com/hphotos-xfp1/t51.2885-15/s150x150/e35/12338585_1668903330056644_140182574_n.jpg",
"width": 150,
"height": 150
"images": {
"low_resolution": {
"url": "https://scontent.cdninstagram.com/hphotos-xap1/t51.2885-15/s320x320/e35/1172990_1289634271062707_99066703_n.jpg",
"width": 320,
"height": 276
},
"thumbnail": {
"url": "https://scontent.cdninstagram.com/hphotos-xap1/t51.2885-15/s150x150/e35/c73.0.934.934/1172990_1289634271062707_99066703_n.jpg",
"width": 150,
"height": 150
/**
* Determines whether the browser supports localStorage or not.
*
* This method is required due to iOS Safari in Private Browsing mode incorrectly says it supports localStorage, when it in fact does not.
*
* @kind function
* @function LocalStorage#supportsLocalStorage
*
* @returns {boolean} Returns true if setting and removing a localStorage item is successful, or false if it's not.
*/