Skip to content

Instantly share code, notes, and snippets.

@mass6
mass6 / Report.php
Created March 29, 2014 12:12
To become Factory
if(file_exists('protected/components/' . $this->reportName . '.php')){
$reportModel = new $this->reportName;
$this->reportTitle = $reportModel->reportTitle;
$this->_report = $reportModel->getReport();
$this->reportContent = $this->_report->report;
$this->downloadableReport = $this->_report->reportGrid;
} else {
$this->reportContent = 'No report of named type ' . $this->reportName ;
}
@mass6
mass6 / SidebarComposer.php
Created February 25, 2015 10:39
Returns the related a an aggregate list of related (many-many) models by the count of related models. Fx. return all tags in order of amount of associated posts they have.
$tagsList = $this->tag->select(DB::raw('tags.name, count(tags.id) as occurrences'))
->join('post_tag', 'tags.id', '=', 'post_tag.tag_id')
->join('posts', 'posts.id', '=', 'post_tag.post_id')
->groupBy('tag_id')
->orderBy('occurrences', 'desc')
->limit(12)
->get();
@mass6
mass6 / PhpUnitAssertionsTrait.php
Created October 11, 2015 20:19
Wrapper for PHPunit Assertions
<?php
trait PhpUnitAssertionsTrait
{
/**
* Asserts that an array has a specified key.
*
* @param mixed $key
* @param array|ArrayAccess $array
@mass6
mass6 / LaravelTrait.php
Created October 12, 2015 13:30
Laravel 5.1 Trait for working with Behat
<?php
use Illuminate\Foundation\Testing\ApplicationTrait;
use Illuminate\Foundation\Testing\AssertionsTrait;
use Illuminate\Foundation\Testing\CrawlerTrait;
use Illuminate\Support\Facades\Artisan;
trait LaravelTrait
{
@mass6
mass6 / LaravelTrait.php
Last active October 13, 2015 12:25
Laravel 4.2 Trait for working with Behat
<?php
use Illuminate\Foundation\Testing\ApplicationTrait;
use Illuminate\Foundation\Testing\AssertionsTrait;
use Illuminate\Support\Facades\Artisan;
trait LaravelTrait
{
/**
@mass6
mass6 / 01.FiniteStateMachine.README.md
Created October 27, 2016 09:13 — forked from tortuetorche/01.FiniteStateMachine.README.md
FiniteStateMachine Trait with Example.Add a DSL to the PHP Finite package, borrowed from the Ruby StateMachine gem.

FiniteStateMachine Trait

Add a DSL to the PHP Finite package, borrowed from the Ruby StateMachine gem.

Usage

In your Stateful Class, add the stateMachineConfig() method and call initStateMachine() method at initialization (__contruct() method).

Example

@mass6
mass6 / FiniteAuditTrailTrait.php
Created October 27, 2016 09:14 — forked from tortuetorche/FiniteAuditTrailTrait.php
FiniteStateMachine and FiniteAuditTrail Traits for Laravel 5.1 (WIP)
<?php namespace App\Finite;
/**
* The FiniteAuditTrail Trait.
* This plugin, for the Finite package (see https://github.com/yohang/Finite), adds support for keeping an audit trail for any state machine.
* Having an audit trail gives you a complete history of the state changes in your stateful model.
* Prerequisites:
* 1. Install Finite package (https://github.com/yohang/Finite#readme)
* 2. Use FiniteStateMachine in your model (https://gist.github.com/tortuetorche/6365575)
* Usage: in your Stateful Class use this trait after FiniteStateMachine trait, like this "use FiniteAuditTrailTrait;".
@mass6
mass6 / 01.EloquentBootSequence.README.md
Last active November 6, 2016 12:29
Eloquent Boot Sequence

Eloquent Boot Sequeence

Demonstrates Laravel's eloquent model boot sequence, including object construction. #

Order of code executed:

  • Static boot method
public static boot(){...}
@mass6
mass6 / 01.FiniteStateMachine.README.md
Last active August 29, 2017 10:19
Laravel 5.3 Finite State Machine Trait
@mass6
mass6 / database.php
Created November 11, 2016 09:28
Connection type for accessing homestead database from host machine
'mysql-local' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost') . ('homestead' == gethostname() ? null : ':33060'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',