Skip to content

Instantly share code, notes, and snippets.

View robertdrakedennis's full-sized avatar

Robert Dennis robertdrakedennis

View GitHub Profile
@robertdrakedennis
robertdrakedennis / GeneratesUuid.php
Last active November 6, 2019 22:08
Simple Laravel UUID4 Generation on bootable models.
<?php
namespace App\Traits\Models;
trait GeneratesUuid
{
/**
* Any model that is in the creating / bootable state will have a UUID 4 created for their primary key.
*
*/
@robertdrakedennis
robertdrakedennis / AccessesRules.php
Last active August 1, 2021 15:48
AccessesRules Trait, used for form requests
<?php
namespace App\Traits;
use Illuminate\Support\Arr;
trait AccessRules
{
public static function getRules(array $only = []): array
{
@robertdrakedennis
robertdrakedennis / GeneratesRandomness.php
Last active October 27, 2019 05:01
Helper for generating a truly random string
<?php
if (! function_exists('randomize')) {
/**
* Generates a random string used for various simple randomness.
*
* @param int $min
* @param int $max
* @param int $limit
* @return string
@robertdrakedennis
robertdrakedennis / _utilities.scss
Created October 22, 2019 13:09
Simple utilities for animation + misc helpers
.background-repeat-none {
background-repeat: no-repeat;
}
.background-size-cover {
background-size: cover;
}
.ease-linear {
transition-timing-function: linear
@robertdrakedennis
robertdrakedennis / GenerateSlug.php
Created October 27, 2019 17:56
Generating and attaching slug to array.
<?php
if (! function_exists('generate_slug')) {
/**
* @param array $data
* @param string $key
* @param bool $unqiue
* @return array
* @throws Exception
*/
@robertdrakedennis
robertdrakedennis / CachesMediaUrl.php
Last active May 30, 2023 18:44
Simple spatie media library caching to avoid n+1 queries
<?php
namespace App\Traits\Models;
trait CachesMediaUrl
{
/**
* Caches Media urls to avoid duplicate calls
@robertdrakedennis
robertdrakedennis / ColorComponent.vue
Created November 11, 2019 08:46
Dead simple way to mount pickr with vue.
<template>
<div>
<input type="hidden" name="color" v-model="color">
<div class="flex flex-row items-center">
<div class="color-picker h-16 w-16 rounded shadow"></div>
<div class="ml-2 text-neutral-200">
<div class="flex flex-col text-sm">
<span>Color:</span>
@robertdrakedennis
robertdrakedennis / TiptapJsonParser.php
Created December 31, 2019 01:58
Super primitive tiptap json parser
<?php
/**
* Strips the json from a tiptap body.
*
* @param array $body
* @return string
*/
function strip_json_body(array $body): string
{
$string = '';
@robertdrakedennis
robertdrakedennis / MongoDatabaseManager.php
Last active April 29, 2021 18:26
a hacky way to have tenants create with mongo
<?php
namespace App\Drivers;
use Illuminate\Database\Connection;
use Illuminate\Support\Facades\DB;
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\Exceptions\NoConnectionSetException;
@robertdrakedennis
robertdrakedennis / SetupEditor.php
Created August 16, 2021 18:26
Server side character counting for tiptap v3
<?php
namespace App\Traits;
trait SetupEditor
{
public function exceedsCharacterCount($delta): bool
{
$renderedHtml = (new \ProseMirrorToHtml\Renderer)->render($delta);