Skip to content

Instantly share code, notes, and snippets.

View adamcrampton's full-sized avatar
💪
Crushing it

Adam Crampton adamcrampton

💪
Crushing it
  • Sydney, Australia
View GitHub Profile
@adamcrampton
adamcrampton / eloquentSearch.php
Created October 28, 2018 23:22
Simple Eloquent search snippet
User::query()
->where('name', 'LIKE', "%{$searchTerm}%")
->orWhere('email', 'LIKE', "%{$searchTerm}%")
->get();
@adamcrampton
adamcrampton / collectionCombiner.php
Created October 28, 2018 23:13
Nested Collection each looping
collect($locales)->each(function (string $locale) {
collect($fields)->each(function (Field $field) use ($locale)
$this->doSomeWork($locale, $field);
});
});
@adamcrampton
adamcrampton / commaStringFormatter.js
Created October 24, 2018 21:14
Takes a comma separated string and replaces the last comma with ", and"
commaStringFormatter = (speechArray) => {
formattedString = [speechArray.slice(0, -1).join(', '), speechArray.slice(-1)[0]].join(speechArray.length < 2 ? '' : ', and ');
return formattedString;
}