Skip to content

Instantly share code, notes, and snippets.

@dillinghamio
dillinghamio / @role.md
Last active April 20, 2021 00:39
@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();

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',