Skip to content

Instantly share code, notes, and snippets.

Brian Dillingham dillinghamio

Block or report user

Report or block dillinghamio

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View new-duedate-conversion.php
$originalStartDate = app('Carbon\Carbon')->parse('1/30/2017');
$newStartDate = app('Carbon\Carbon')->parse('2/27/2017');
$difference = $originalStartDate->diffInDays($newStartDate);
$dates = [
View Laravel Model Scope

Laravel Model Scope Array

Use array syntax to define a list of scopes to apply to a model

Assuming you have scopePopular & scopeRecent as query scopes

Book::scopes(['popular', 'recent'])->get();

Add this to your model

View session('db') - query

Laravel Query Dump: count, time, and objects

session('db') using code below, will produce query count, time spent, and the query objects themselves

\DB::listen(function ($query) {
        session()->push('db.queries', $query);
        $queries = collect(session('db.queries'));
dillinghamio /
Last active May 30, 2019
@ROLE Blade Directive For Laravel Spark

@role Blade Directive For Laravel Spark

Assumes you're using teams

Add this to the boot() method of your AppServiceProvider

\Blade::directive('role', function($roles) {

        $user = auth()->user();

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 /
Last active Aug 13, 2019
Team Role Middleware For Laravel Spark

Team Role Middleware For Laravel Spark

Makes it simple to use Spark's role feature on routes

Route::group(['middleware'=>'role:owner'], function(){
    // owners only

Route::group(['middleware'=>'role:member'], function(){

User's Fellow Members in Laravel Spark

add to your user model

public function teamMembers($role='member')
    return $this->currentTeam
View Spark User Team

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,
dillinghamio /
Last active Apr 30, 2019
Laravel Spark @plan Blade Directive

@plan Blade Directive For Laravel Spark

Works with user & team billing

Add this to the boot() method of your AppServiceProvider

\Blade::directive('plan', function($plans) {

        $model = auth()->user();
dillinghamio / Notification Helper For Laravel
Last active Jan 18, 2019
Notification Helper For Laravel Spark
View Notification Helper For Laravel

notification Helper For Laravel Spark

The method assumes the current authenticated user, so you only need to pass the message

function notification($message)
	$notification = app('Laravel\Spark\Contracts\Repositories\NotificationRepository');
	return $notification->create(auth()->user(), $message);
You can’t perform that action at this time.