Skip to content

Instantly share code, notes, and snippets.

@dillinghamio
dillinghamio / gist:056dc42f9238ce0005ef
Last active August 29, 2015 14:06
Add Selectable Indentation for code output dynamically.
var indentElements = $('[class*="tab-"]');
$.each(indentElements, function (index) {
var indentAmount = parseInt(this.className.split('-')[1]);
var indentation = new Array(indentAmount + 1).join('    ');
this.innerHTML = indentation + this.innerHTML
});

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) {
    if(app()->isLocal())
    {
        session()->push('db.queries', $query);
 $queries = collect(session('db.queries'));

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

$originalStartDate = app('Carbon\Carbon')->parse('1/30/2017');
$newStartDate = app('Carbon\Carbon')->parse('2/27/2017');
$difference = $originalStartDate->diffInDays($newStartDate);
$dates = [
'2/20/2017',
'2/24/2017',
'3/6/2017',
@dillinghamio
dillinghamio / Notification Helper For Laravel Spark.md
Last active January 18, 2019 08:14
Notification Helper For Laravel Spark

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);
@dillinghamio
dillinghamio / laravel-spark-rotating-pricing-table.md
Last active August 13, 2019 13:53
Laravel Spark Pricing Table

Rotating Pricing Table for Laravel Spark

Can be placed anywhere, try it out on welcome.blade.php


Laravel Spark Pricing Table ###If you're using team plans just swap out $sparkPlans = Spark::plans(); with $sparkPlans = Spark::teamPlans();


@dillinghamio
dillinghamio / currentTeamMembersByRole.md
Last active August 13, 2019 13:55
currentTeamMembersByRole

User's Fellow Members in Laravel Spark

add to your user model

public function teamMembers($role='member')
{
    return $this->currentTeam
 ->users()

##Team Dropdown for Laravel Spark

Maybe you want a way for users to quickly jump to team settings?

Can be placed anywhere, try it out on user-right.blade.php Laravel Spark Team Dropdown

<?php $currentTeam = auth()->user()->currentTeam; ?>
@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' =&gt; $faker-&gt;sentence,
@dillinghamio
dillinghamio / @plan.md
Last active December 26, 2020 13:24
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()-&gt;user();