Skip to content

Instantly share code, notes, and snippets.

@edgrosvenor
edgrosvenor / RunPlanetScaleMigrations.php
Created September 28, 2022 09:39
The current state of my attempt to fully automate migrations upon deployment with PlanetScale
<?php
namespace App\Console\Commands\CI;
use App\Support\PlanetScale\CategorizeMigrations;
use App\Support\PlanetScale\ConnectToBranch;
use App\Support\PlanetScale\CreateBranch;
use App\Support\PlanetScale\CreateDeployRequest;
use App\Support\PlanetScale\DeleteBranch;
use App\Support\PlanetScale\DeployRequest;
@edgrosvenor
edgrosvenor / Exportable.php
Created February 20, 2022 02:14
Zero effort export to csv for Eloquent models
<?php
namespace App\Traits;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use ReflectionClass;
trait Exportable
{
<?php
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
$rules = [
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'assign_null_coalescing_to_coalesce_equal' => true,
'binary_operator_spaces' => [
<?php
namespace App\CampFormats;
use App\Actions\CopyPdfFromResources;
use App\Actions\CreateRosterPdf;
use App\Actions\GetGoogleDocAsPdf;
class BasketballOneDay extends BaseFormat
{
@edgrosvenor
edgrosvenor / SignedOrLoggedIn.php
Last active July 22, 2021 07:02
A quick and easy way to let authenticated users share the current page using a temporary signed url.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class SignedOrLoggedIn
{
/**
@edgrosvenor
edgrosvenor / to_data_get.php
Created June 14, 2021 18:11
Hacky script I ran in Tinkerwell to replace direct array access with data_get() in blade templates. Mostly works.
foreach (\File::files(resource_path('views')) as $file) {
if (str_contains($file->getPathname(), 'blade.php')) {
$contents = \File::get($file);
$contents = str_replace('{{', '{{ ', $contents);
$contents = str_replace('}}', ' }}', $contents);
$contents = str_replace('])', '] )', $contents);
preg_match_all('/\$[a-zA-Z](.*?)[ \}]/', $contents, $match);
$replace = [];
@edgrosvenor
edgrosvenor / LocalOnly.php
Created February 12, 2021 17:46
I register this as a route middleware in any app I build to keep me from enabling my really hacky shortcuts in production.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class LocalOnly
{
/**
@edgrosvenor
edgrosvenor / OkuCalculator.php
Created January 30, 2021 16:15
oku yen to usd artisan command
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class OkuCalculator extends Command
{
/**
* The name and signature of the console command.
@edgrosvenor
edgrosvenor / CodeBlock.php
Created November 23, 2020 20:06
Displaying blade component tags in a code block in Laravel
<?php
namespace App\View\Components;
use Illuminate\View\Component;
class CodeBlock extends Component
{
/**
* Create a new component instance.
@edgrosvenor
edgrosvenor / College.php
Created August 30, 2020 17:15
A POINT column, left to its own devices, results in a messy attempt at a string when sent through ->toArray()
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class College extends Model
{
protected $connection = 'v1';
protected $table = 'colleges_colleges';