Skip to content

Instantly share code, notes, and snippets.

View adamfairholm's full-sized avatar

Adam Fairholm adamfairholm

View GitHub Profile
@adamfairholm
adamfairholm / gist:af88caf5bd0e585154ed
Last active March 24, 2016 01:41
Laravel's where date functions.
<?php
// Laravel has some date functions in the query builder that I never really
// see mentioned. Most of the time when a user needs to do a MONTH(col) select,
// they are advised to do something like this:
$employees = Employee::where(DB::Raw('MONTH(hired_at)'), '=', 4)->get();
// However, Laravel seems to have query builder functions that take care of this.
// The above query could be rewritten as:
$employees = Employee::whereMonth('hired_at', '=', 4)->get();
### Keybase proof
I hereby claim:
* I am adamfairholm on github.
* I am adamfairholm (https://keybase.io/adamfairholm) on keybase.
* I have a public key whose fingerprint is 37ED C3E3 611C E8F4 D0C3 6EEF 6C70 60D0 61B3 C170
To claim this, I am signing this object:
@adamfairholm
adamfairholm / gist:6187443
Last active December 20, 2015 19:59
Fix for recaptcha:
In the streams/plugin.php file, find this line in the form() function (around line 760):
if ($recaptcha)
Under that, you should see:
$this->recaptcha->_rConfig['theme'] = $this->streams_attribute('recaptcha_theme', 'red');
Just above that line, add:
{{ query:run select="DISTINCT nominee_state" from="nominees" }}
<h1>{{nominee_state}}</h1>
{{ streams:cycle stream="nominees" include=nominee_state include_by="nominee_state" }}
<h3>{{nominee_name}}</h3>
{{ /streams:cycle }}
{{ /query:run }}
{{ query:run select="DISTINCT nominee_year" from="nominees" }}
<option value="{{ nominee_year }}">
{{ nominee_year }}
</option>
{{ /query:run }}
public function add_field_to_stream($field_id, $stream_id, $data, $create_column = true)
{
// -------------------------------------
// Get the field data
// -------------------------------------
$field = $this->fields_m->get_field($field_id);
if ( ! $field) {
die('no field');
@adamfairholm
adamfairholm / gist:5444337
Last active December 16, 2015 13:49
New pagination options in PyroCMS 2.2.1
// You can specify two new things in streams for PyroCMS 2.2.1:
// 1. pag_uri_method - Set it to 'query_string', so you can do /my-uri?page=2. Defaults to segment - /my-uri/2.
// 2. pag_method - Allows you to set if the value in the URI should be the offset or the page number.
{{ streams:sample paginate="yes" pag_uri_method="query_string" pag_method="page" }}
<p>{{ var }}</p>
{{ /streams:sample }}
{{ streams:cycle stream="example" where="`category_field_slug`='[segment_2]'" }}
public function lang_var()
{
$vars = $this->load->get_vars();
$var = $this->attribute('var');
// Do we have our page
if (isset($vars['page'])) {
$page = $vars['page'];
}
@adamfairholm
adamfairholm / gist:5292754
Created April 2, 2013 14:42
Passthrough Vars Feature for PyroStreams
// -------------------------------------
// Keep Vars
// -------------------------------------
// Allow vars to pass through by doing
// keep:{var_name}={var_value}
// -------------------------------------
$keepers = array();
foreach ($this->attributes() as $key => $val)