Skip to content

Instantly share code, notes, and snippets.

@AdenFraser
AdenFraser / firstOr.php
Last active April 28, 2018 21:57
Laravel firstOr Collection Macro
<?php
use Illuminate\Support\Collection;
/*
* Get the first item. Performs callback if the item was not found.
*
* @return mixed
*/
Collection::macro('firstOr', function (callable $callback) {
@AdenFraser
AdenFraser / appends.sublime-snippet
Last active July 22, 2016 14:06
Laravel Model Sublime Snippets
<snippet>
<content><![CDATA[
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected \$appends = [
'${1}',
];
@AdenFraser
AdenFraser / gist:c88598b1c6cf2c7f6a10
Created March 1, 2015 18:06
Alternate between odd and even classes in a loop
<div class="<?php $oddEven = ($oddEven=='odd') ? 'even':'odd'; echo $oddEven; ?>">
</div>