Skip to content

Instantly share code, notes, and snippets.

View simonhamp's full-sized avatar
💭
Accidentally learning Rust

Simon Hamp simonhamp

💭
Accidentally learning Rust
View GitHub Profile
@simonhamp
simonhamp / Reroutable.php
Created December 5, 2023 14:35
A trait to reroute Laravel Notifications at runtime
<?php
namespace App\Concerns\Notifications;
trait Reroutable
{
protected array $routes;
public function routes(string ...$routes): static
{
@simonhamp
simonhamp / TreeSplit.php
Created May 26, 2022 02:06
Split a Statamic Tree into two collections
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Statamic\Facades\Collection;
use Statamic\Eloquent\Entries\UuidEntryModel as EntryModel;
use Statamic\Facades\Entry;
use Statamic\Structures\CollectionTree;
@simonhamp
simonhamp / MigrateUsers.php
Last active February 1, 2024 10:16
Migrate Statamic v3 file-based users to a database
<?php
/**
* Statamic v3 User Migrator
* @author Simon Hamp <simon.hamp@me.com>
* @copyright Copyright (c) 2021, Simon Hamp
* @license MIT
*/
namespace App\Console\Commands;
use Exception;
@simonhamp
simonhamp / ScheduleListCommand.php
Created January 6, 2021 13:12
Laravel: Back-port the schedule:list command
<?php
namespace App\Console\Commands;
use Cron\CronExpression;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Console\Scheduling\Schedule;
class ScheduleListCommand extends Command
@simonhamp
simonhamp / WebhookController.php
Last active November 17, 2023 17:13
Handling Typeform Webhooks in Laravel
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class WebhookController
{
public function create(Request $request)
{
@simonhamp
simonhamp / StachePrimeCommand.php
Created May 22, 2020 14:33
Prime your Stache
<?php
namespace Statamic\Addons\MyAddon\Commands;
use Statamic\API\Stache;
use Statamic\Extend\Command;
class StachePrimeCommand extends Command
{
/**
@simonhamp
simonhamp / quotes.md
Last active April 23, 2019 17:59
Some quotes and their sources

"A lot of times, you open up some code for something simple like this, and you find that it is just a massive tangle of unnecessary structure and indirection."

Casey Muratori 2014-05-28 (Retrieved 2018-05-18)

"Frameworks are not tools for organising your code, they are tools for organising your mind."

Rich Harris Code Camp 2019 (Retrieved 2019-04-23)

@simonhamp
simonhamp / AppServiceProvider.php
Last active February 6, 2023 03:19
Laravel: Str::csvToArray macro
<?php
namespace App\Providers;
use Illuminate\Support\Str;
class AppServiceProvider extends ServiceProvider
{
public function boot()
@simonhamp
simonhamp / VersionMatcher.php
Created January 18, 2018 12:16
A simple SemVer parser/matcher
<?php
class VersionMatcher
{
protected $specificity = 'major';
protected $originals = [];
protected $current;
protected $target;
protected static $padDigits;
@simonhamp
simonhamp / BaseModel.php
Last active March 25, 2020 16:57
Eloquent: Simple Model Event Handling
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class BaseModel extends Model
{
/**
* Override the default boot method to register some extra stuff for every child model.