Skip to content

Instantly share code, notes, and snippets.

@muskie9
Created July 9, 2015 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muskie9/2542df4d062f764f64ba to your computer and use it in GitHub Desktop.
Save muskie9/2542df4d062f764f64ba to your computer and use it in GitHub Desktop.
Assumes at least 4 Testimonials are <= 750 characters. Doesn't get 2 random, sort is always the same.
public function getTestimonials(){
return Testimonial::get()
->filterByCallback(
function($item, $list) {
return strlen($item->Description) <= 750;
}
)
->sort('RAND()')
->limit(2);
}
@muskie9
Copy link
Author

muskie9 commented Jul 9, 2015

Solved: ->sort('RAND()') needs to come before ->filterByCallback()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment