Skip to content

Instantly share code, notes, and snippets.

View stevebauman's full-sized avatar
💎
Sparklin’

Steve Bauman stevebauman

💎
Sparklin’
View GitHub Profile
{
"version": "1.24.4",
"modified": true,
"page": {
"editors": [
{
"id": "4cd30d03-dc95-4a19-807e-7ca9551f28cb",
"added": [],
"removed": [],
"focused": [],
@stevebauman
stevebauman / User.php
Created May 28, 2024 17:07
Enum Based Laravel Media Collection Registration
<?php
namespace App\Models;
// ...
use App\Enums\UserMediaCollection;
class User extends Authenticatable
{
// ...
@stevebauman
stevebauman / RouteServiceProvider.php
Last active May 14, 2024 02:19
Throw exception on Eloquent model binding name mismatch
<?php
namespaced App\Providers;
use RuntimeException;
use Illuminate\Support\Facades\Route;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Routing\ImplicitRouteBinding;
class RouteServiceProvider extends ServiceProvider
@stevebauman
stevebauman / Utility.php
Created January 19, 2024 21:52
All Tailwind Utilities in PHP with their matching regex patterns
<?php
namespace App;
class Utility
{
/**
* The registered utilities.
*/
protected static array $utilities = [];
@stevebauman
stevebauman / FilesystemMockProvider.php
Created February 17, 2023 17:19
Filesystem Cloud Mocking
<?php
namespace App\Providers;
class FilesystemMockProvider extends ServiceProvider
{
public function boot()
{
if (App::isProduction()) {
return;
@stevebauman
stevebauman / Mutable.php
Created February 16, 2023 14:50
Mutable Observers
<?php
namespace App\Observers;
trait Mutable
{
public static function mute(string|array $events = null)
{
if (is_null($events)) {
$events = ['*'];
@stevebauman
stevebauman / timezones.php
Created May 19, 2022 13:56
Human Friendly Timezone List Generator PHP
$timezones = array_map(function ($timezone) {
$date = new DateTime('now', $tz = new DateTimeZone($timezone));
return [
'timezone' => $timezone,
// Format: "(GMT -05:00) America/Toronto"
'label' => "({$date->format('\G\M\T P')}) {$tz->getName()}",
];
}, DateTimeZone::listIdentifiers());
@stevebauman
stevebauman / timezones.php
Created May 19, 2022 13:31
Laravel PHP Timezones to Human Friendly
return [
'Pacific/Midway' => 'Midway Island, Samoa',
'Pacific/Honolulu' => 'Hawaii',
'America/Anchorage' => 'Alaska',
'America/Tijuana' =>
'Pacific Time (US and Canada); Tijuana, Baja California',
'America/Edmonton' => 'Mountain Time (US and Canada)',
'America/Chihuahua' => 'Chihuahua, La Paz, Mazatlan',
'America/Phoenix' => 'Arizona',
'America/Chicago' => 'Central Time (US and Canada)',
@stevebauman
stevebauman / AuthServiceProvider.php
Last active November 11, 2021 21:44
A Laravel Sanctum "token" User provider
<?php
Auth::provider('sanctum:token', function ($app, $config) {
return new SanctumTokenUserProvider($app['hash'], $config['model']);
});
@stevebauman
stevebauman / clipboard.js
Last active October 12, 2021 11:02
Copy Rich Text to Clipboard Cross Platform & Browser
/**
* Copy rich text content to clipboard.
*
* Must be initiated by a user click event.
*
* @param {string} content
*/
export default function (content) {
const selection = window.getSelection();