Skip to content

Instantly share code, notes, and snippets.

@JonoB
JonoB / gist:6637861
Created September 20, 2013 13:49
Laravel Base Model
<?php namespace Tmb;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Validation\Validator;
class BaseModel extends Eloquent
{
/**
* Error message bag
@JonoB
JonoB / gist:6917686
Last active December 25, 2015 04:29
var response = { 'whatever' };
var items = ['item1', 'Item2', 'Item3'];
$.each(items, function(key, value) {
$.each(response.value, function(k, v) {
});
});
@JonoB
JonoB / eager-load-relations-repository
Last active December 20, 2015 12:19
Eager loading relationships in a repository
// If we have a model that has a lot of relationships, we need a method to be able to dynamically
// eager-load those relationships in an easy way
// For example, some controller methods may only require one relationship to be loaded
// Others may require all relationships to be eager loaded
// Repository
class UserRepository implements UserInterface
{
public function find($id, $relations = array())
@JonoB
JonoB / IncrementMonths.php
Created October 28, 2015 15:32
Increment PHP Months
$nextMonthDate = $date->copy();
$nextMonthDate->addMonths($addMonths);
// j - Day of the month without leading zeros
if ($nextMonthDate->format('j') != $date->format('j'))
{
$date->modify('last day of +'.$addMonths.' months');
}
else
{
@JonoB
JonoB / gist:de0af1bfb34666e887d6
Last active August 29, 2015 14:22
Laravel Upgrade Form helpers from L4 to L5
Regex search and replace for form helpers as follows:
Search:
\{\{ (Form\:\:.+) \}\}
Replace:
{!! $1 !!}