Skip to content

Instantly share code, notes, and snippets.

@JonoB
JonoB / IncrementMonths.php
Created Oct 28, 2015
Increment PHP Months
View IncrementMonths.php
$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 Aug 29, 2015
Laravel Upgrade Form helpers from L4 to L5
View gist:de0af1bfb34666e887d6
Regex search and replace for form helpers as follows:
Search:
\{\{ (Form\:\:.+) \}\}
Replace:
{!! $1 !!}
View gist:6917686
var response = { 'whatever' };
var items = ['item1', 'Item2', 'Item3'];
$.each(items, function(key, value) {
$.each(response.value, function(k, v) {
});
});
@JonoB
JonoB / gist:6637861
Created Sep 20, 2013
Laravel Base Model
View gist:6637861
<?php namespace Tmb;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Validation\Validator;
class BaseModel extends Eloquent
{
/**
* Error message bag
@JonoB
JonoB / eager-load-relations-repository
Last active Dec 20, 2015
Eager loading relationships in a repository
View eager-load-relations-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())