Skip to content

Instantly share code, notes, and snippets.

@edgrosvenor
edgrosvenor / phpunit.xml
Created March 10, 2020 12:33
Use Collision's PHPUnit Printer Driver by Default
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
printerClass="NunoMaduro\Collision\Adapters\Phpunit\Printer">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class SetRepositories extends Command
{
@edgrosvenor
edgrosvenor / route-error.php
Last active June 6, 2020 19:35
An interesting error encountered in Laravel the route name as a string is returned by the route
Route::group(['prefix' => 'coach/{coach}', 'middleware' => 'auth:coaches'], function() {
Route::get('/', function() { return 'Hello coach-dashboard how are you'; })->name('coach-dashboard');
});
// Log: [2020-06-06 19:24:04] testing.ERROR: Maximum function nesting level of '256' reached, aborting! {"userId":1,"exception":"[object] (Error(code: 0): Maximum function nesting level of '256' reached, aborting! at /Users/ed/Sites/exactsports/virtual-camp/vendor/laravel/framework/src/Illuminate/Container/Container.php:772)
@edgrosvenor
edgrosvenor / dev.json
Last active July 4, 2020 14:18
Experimenting with wikimedia/composer-merge-plugin
{
"require": {
"grosv/eloquent-sheets": "dev-main",
"grosv/laravel-passwordless-login": "dev-main",
"wikimedia/composer-merge-plugin": "^1.4"
},
"require-dev": {
"grosv/laravel-git-workflow": "dev-main",
"grosv/stubby": "dev-main"
},
@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';
@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 / 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 / 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 / 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 / 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
{
/**