Skip to content

Instantly share code, notes, and snippets.

View shawnlindstrom's full-sized avatar
🤦‍♂️

Shawn Lindstrom shawnlindstrom

🤦‍♂️
View GitHub Profile
@shawnlindstrom
shawnlindstrom / example.php
Created October 28, 2022 04:00
Using PDO from the DB facade for a complex query
$sql = "SELECT tblSU.Site,
tlkpSUDesc.ESR_SUcat,
tlkpSUDesc.ESR_SUcatdisp,
tlkpSUDesc.SUDesc,
tlkpSUTyp.SUTyp,
tblSU.SUNum
FROM tlkpSUTyp
RIGHT JOIN (tlkpSUDesc RIGHT JOIN tblSU ON tlkpSUDesc.SUDescCode = tblSU.SUDescCode)
ON tlkpSUTyp.SUTypCode = tblSU.SUTypCode
WHERE tblSU.Site = :id
@shawnlindstrom
shawnlindstrom / retry-queue-job-by-date
Created August 8, 2022 16:29
Retry a failed Laravel queue job for a specific date
/**
* @credit Luke Waite
* @see https://lukewaite.ca/posts/2017/08/17/bash-oneliner-laravel-retry-todays-failed-jobs.html
*
* See the explanation in Luke's post for the following Bash one liner to retry
* a failed queue job for a specific date. The only difference in this version
* is {print $2} needs to be {print $3} because the output of queue:failed has
* changed. Works for Laravel 9.
*
* Running the following line will retry all failed jobs from 8/8/2022.
@shawnlindstrom
shawnlindstrom / Laravel whereBetweenDates Macro
Last active February 11, 2022 20:02
Laravel Builder Macro for whereBetweenDates
/** Add to your \App\Providers\AppServiceProvider.php or php artisan make:provider MacroServiceProvider
* and register your new provider in config/app.php
*/
public function register()
{
\Illuminate\Database\Eloquent\Builder::macro('whereBetweenDates', function (string $column, array $values) {
[$start, $end] = $values;
return $this->getQuery()
@shawnlindstrom
shawnlindstrom / MacroServiceProvider
Created August 13, 2021 20:02
Laravel to SQL with Bindings Macro
<?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 September 11, 2019 06:26
Demonstrates That Month Addition Results in Overflow And How To Fix
<?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 March 15, 2023 13:49
Laravel Validation String for US Zip Code
'regex:/^[0-9]{5}(?:-[0-9]{4})?$/'
@shawnlindstrom
shawnlindstrom / retry.php
Last active November 27, 2018 21:34
PHP Try/Retry on Exception
<?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 July 4, 2018 03:00
Twilio Service Provider for Laravel
<?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 April 24, 2018 03:29
A helper to derive timezone from phone numbers using giggsey/libphonenumber-for-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 June 14, 2016 20:21 — forked from jamesfairhurst/PasswordBroker.php
Laravel 5.2 Queue Password Reset Email
<?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