Skip to content

Instantly share code, notes, and snippets.

Avatar
🤦‍♂️

Shawn Lindstrom shawnlindstrom

🤦‍♂️
View GitHub Profile
@shawnlindstrom
shawnlindstrom / MacroServiceProvider
Created Aug 13, 2021
Laravel to SQL with Bindings Macro
View MacroServiceProvider
<?php
namespace App\Providers;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;
class MacroServiceProvider extends ServiceProvider
{
@shawnlindstrom
shawnlindstrom / CarbonNextMonthEndOfMonthTest.php
Created Sep 11, 2019
Demonstrates That Month Addition Results in Overflow And How To Fix
View CarbonNextMonthEndOfMonthTest.php
<?php
namespace Tests\Unit;
use Tests\TestCase;
class CarbonNextMonthEndOfMonthTest extends TestCase
{
public function setUp(): void
{
@shawnlindstrom
shawnlindstrom / laravel-validation-string-for-us-zip-code.txt
Last active Jul 11, 2019
Laravel Validation String for US Zip Code
View laravel-validation-string-for-us-zip-code.txt
'regex:/^[0-9]{5}(?:-[0-9]{4})?$/'
@shawnlindstrom
shawnlindstrom / retry.php
Last active Nov 27, 2018
PHP Try/Retry on Exception
View retry.php
<?php
/**
* Basic structure for retrying when an exception is thrown in a try/catch block.
* This example fails through three retries simply to illustrate the behavior.
*/
$retries = 3;
for ($try = 0; $try < $retries; $try++) {
try {
@shawnlindstrom
shawnlindstrom / TwilioServiceProvider.php
Created Jul 4, 2018
Twilio Service Provider for Laravel
View TwilioServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Twilio\Rest\Client as TwilioService;
class TwilioServiceProvider extends ServiceProvider
{
public function register()
@shawnlindstrom
shawnlindstrom / PhoneToTimezone.php
Created Apr 24, 2018
A helper to derive timezone from phone numbers using giggsey/libphonenumber-for-php
View PhoneToTimezone.php
<?php
use libphonenumber\NumberParseException;
use libphonenumber\PhoneNumberToTimeZonesMapper;
use libphonenumber\PhoneNumberUtil;
if (!function_exists('phone_to_timezone')) {
/**
* Returns a timezone for a phone number. Note, multiple timezones are
* possible for non-US regions. Only the first timezone is returned.
@shawnlindstrom
shawnlindstrom / PasswordBroker.php
Created Jun 14, 2016 — forked from jamesfairhurst/PasswordBroker.php
Laravel 5.2 Queue Password Reset Email
View PasswordBroker.php
<?php
namespace App;
use Illuminate\Auth\Passwords\PasswordBroker as IlluminatePasswordBroker;
class PasswordBroker extends IlluminatePasswordBroker
{
/**
* Send the password reset link via e-mail in a queue