Skip to content

Instantly share code, notes, and snippets.

View njames's full-sized avatar

Nigel James njames

View GitHub Profile

UsedByTeams Model Trait For Laravel Spark

Automatically limit your models to the current team

So you're using spark, and you have teams enabled. You start creating models and want to have them be team specific. Instead of writing, Model::where('team_id', auth()->user()->currentTeam->id)->get(); use this trait to add that behind the scenes so that every time you call on your model, it's assumed that you mean for the current team.

This assumes that the model has a team_id, while it adds a scope of where team_id = currentTeam->id.

Note: Implicit Route Model Binding in 5.2, auth session doesn't exist at the point of this trait causing issue. fixed in 5.3

@dillinghamio
dillinghamio / Spark User Team Seeding.md
Last active November 23, 2020 13:07
Spark User Team Seeding

Seeding Users & Teams In Laravel Spark

Makes 5 users each with 1 team that has 5 members

Add a team factory to database/factories/ModelFactory.php

$factory->define(App\Team::class, function (Faker\Generator $faker) {
    return [
 'name' => $faker->sentence,
@QuantumGhost
QuantumGhost / example.puml
Last active March 23, 2024 22:39
A simple template for PlantUML to draw ER diagram.The basic idea comes from http://plantuml.sourceforge.net/qa/?qa=331/database-modeling
@startuml
' uncomment the line below if you're using computer with a retina display
' skinparam dpi 300
!define Table(name,desc) class name as "desc" << (T,#FFAAAA) >>
' we use bold for primary key
' green color for unique
' and underscore for not_null
!define primary_key(x) <b>x</b>
!define unique(x) <color:green>x</color>
!define not_null(x) <u>x</u>
@mitsuruog
mitsuruog / bind.js
Last active April 6, 2018 01:11
multiple property databinding on SAPUI5
new sap.m.Text({
text: {
parts: [
{path: "Width"},
{path: "Depth"},
{path: "Height"},
{path: "DimUnit"}
],
formatter: function(width, depth, height, dimUnit){
return width + " x " + depth + " x " + height + " " + dimUnit;
@whatnickcodes
whatnickcodes / base64.js
Created April 24, 2014 15:01
How to Encode and Decode Strings with Base64 in JavaScript
// Create Base64 Object
var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(f<e.length){s=this._keyStr.indexOf(e.charAt(f++));o=this._keyStr.indexOf(e.charAt(f++));u=this._keyStr.indexOf(e.charAt(f++));a=this._keyStr.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r
@rothgar
rothgar / main.yml
Last active March 8, 2024 07:16
Generate /etc/hosts with Ansible
# Idempotent way to build a /etc/hosts file with Ansible using your Ansible hosts inventory for a source.
# Will include all hosts the playbook is run on.
# Inspired from http://xmeblog.blogspot.com/2013/06/ansible-dynamicaly-update-etchosts.html
- name: "Build hosts file"
lineinfile: dest=/etc/hosts regexp='.*{{ item }}$' line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}" state=present
when: hostvars[item].ansible_default_ipv4.address is defined
with_items: groups['all']
@denji
denji / http-benchmark.md
Last active May 2, 2024 06:26
HTTP(S) Benchmark Tools / Toolkit for testing/debugging HTTP(S) and restAPI (RESTful)
@JDMcKinstry
JDMcKinstry / apiCCB.php
Last active July 22, 2019 18:39
Simple PHP class for interacting with the Church Community Builder (CCB) API.
<?
/***
* class apiCCB
*
* @author Jeremiah D. McKinstry <jdmckinstry@gmail.com>
* @date Wednesday, August 14, 2013
* @version 1.0.0
* @see https://cdn6.ccbchurch.com/2/documents/pwt_implement.pdf
*
* @copyright This class is free: you can redistribute it and/or modify
@elsewhat
elsewhat / sapui5_sources_latest.sh
Created July 26, 2013 13:32
Get latest SAPUI5 for eclipse update site
#!/bin/bash
echo "1. Download the main file from the eclipse update site"
wget --no-check-certificate https://tools.hana.ondemand.com/juno/content.jar
echo "2. Unzip the content.jar to content.xml (and delete content.jar)"
unzip content.jar
rm content.jar
echo "3. Generate urls for the components to fetch com.sap.ui5"
@viniciustavanoferreira
viniciustavanoferreira / Z_RTTI_VTF.abap
Created May 21, 2013 17:42
Run Time Type Identification (example).
*&---------------------------------------------------------------------*
*& Report Z_RTTI_VTF
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_RTTI_VTF.
TYPES in_type TYPE i.