Skip to content

Instantly share code, notes, and snippets.

View stevebauman's full-sized avatar
💎
Sparklin’

Steve Bauman stevebauman

💎
Sparklin’
View GitHub Profile
@stevebauman
stevebauman / RouteServiceProvider.php
Last active May 10, 2024 20:50
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();
@stevebauman
stevebauman / vue-datatables.vue
Last active March 4, 2022 00:51
Vue DataTables (Vue 3)
<template>
<div :class="classes">
<table v-once :id="tableId" ref="table" :class="className" cellpadding="0">
<thead :class="theadClassName">
<tr>
<th v-for="(field, i) in options.columns" :key="'head_' + i" :class="field.classHeaderName">
<slot :name="'HEAD_' + field.name" :field="field" :i="i">
<input
v-if="field.name === '_select_checkbox'"
type="checkbox"
@stevebauman
stevebauman / fix-style.yml
Last active March 15, 2024 20:51
PHP CS Fixer GitHub Action
name: fix-style
on:
push:
pull_request:
paths:
- '**.php'
jobs:
php-cs-fixer: