Skip to content

Instantly share code, notes, and snippets.

View davidjpella's full-sized avatar
🏠
Working from home

David Pella davidjpella

🏠
Working from home
View GitHub Profile

Tappable Scopes in Laravel

The Problem

  • Laravel's model scopes don't work with Scout (search).
  • Reusing scopes across models means copying code OR using traits (but Scout still breaks).
  • Leads to duplicate query logic.

The Solution: Tappable Scopes

Instead of defining scopes inside models, create scope classes that can be used in both Eloquent & Scout queries!

@davidjpella
davidjpella / rm_mysql.md
Created September 15, 2024 06:38 — forked from vitorbritto/rm_mysql.md
Remove MySQL completely from Mac OSX

Remove MySQL completely

  1. Open the Terminal

  2. Use mysqldump to backup your databases

  3. Check for MySQL processes with: ps -ax | grep mysql

  4. Stop and kill any MySQL processes

  5. Analyze MySQL on HomeBrew:

    brew remove mysql
    
@davidjpella
davidjpella / blob-filereader-localStorage.js
Created April 4, 2024 15:39 — forked from robnyman/blob-filereader-localStorage.js
Get file as a blob, read through FileReader and save in localStorage
// Getting a file through XMLHttpRequest as an arraybuffer and creating a Blob
var rhinoStorage = localStorage.getItem("rhino"),
rhino = document.getElementById("rhino");
if (rhinoStorage) {
// Reuse existing Data URL from localStorage
rhino.setAttribute("src", rhinoStorage);
}
else {
// Create XHR and FileReader objects
var xhr = new XMLHttpRequest(),
@davidjpella
davidjpella / useBroadcastChannel.ts
Created February 18, 2024 11:27 — forked from KristofferEriksson/useBroadcastChannel.ts
A React hook that allows you to send and receive messages between browser tabs or windows
import { useCallback, useEffect, useRef, useState } from "react";
interface UseBroadcastChannelOptions {
name: string;
onMessage?: (event: MessageEvent) => void;
onMessageError?: (event: MessageEvent) => void;
}
interface UseBroadcastChannelReturn<D, P> {
isSupported: boolean;
@davidjpella
davidjpella / useUndo.ts
Created January 31, 2024 12:31 — forked from KristofferEriksson/useUndo.ts
A React hook that enhances your components with powerful undo/redo functionality
import { useCallback, useEffect, useRef, useState } from "react";
interface UseUndoHook<T> {
value: T;
onChange: (newValue: T) => void;
undo: () => void;
redo: () => void;
clear: () => void;
canUndo: boolean;
canRedo: boolean;
@davidjpella
davidjpella / .Laravel-Jetstream-Inertia.md
Created July 6, 2022 15:32 — forked from kossoy/.Laravel-Jetstream-Inertia.md
Setup project with Laravel, Jetstream (FB and Google through Socialite), and Inertia.js with Vue.js
@davidjpella
davidjpella / CheckBox.vue
Created October 4, 2021 11:25 — forked from Jonarod/CheckBox.vue
Simple custom CheckBox component for Vue.js, compatible with v-model.
/**
* @usage:
*
* <CheckBox label="Foo" value="foo" v-model="MySelectedValues" />
* <CheckBox label="Bar" value="bar" v-model="MySelectedValues" />
* <CheckBox label="Baz" value="baz" v-model="MySelectedValues" />
*
* data(){
* return {
* MySelectedValues: [],
@davidjpella
davidjpella / AddressInput.vue
Created February 12, 2021 17:34 — forked from reinink/AddressInput.vue
Multiple v-models in Vue 3
<template>
<input type="text" :value="address" @input="$emit('update:address', $event.target.value)">
<input type="text" :value="city" @input="$emit('update:city', $event.target.value)">
<input type="text" :value="region" @input="$emit('update:region', $event.target.value)">
<input type="text" :value="country" @input="$emit('update:country', $event.target.value)">
<input type="text" :value="postal" @input="$emit('update:postal', $event.target.value)">
</template>
<script setup>
import { defineProps } from 'vue'
@davidjpella
davidjpella / responsive-menu.html
Created January 6, 2021 18:21 — forked from Akryum/responsive-menu.html
Tailwind negate responsive breakpoints
<div class="flex !md:flex-col items-center !md:space-y-6 md:space-x-6">
<button>Menu button 1</button>
<button>Menu button 2</button>
<button>Menu button 3</button>
</div>
@davidjpella
davidjpella / query.sql
Created April 26, 2020 14:01 — forked from reinink/query.sql
Text search across multiple tables using MySQL
select
first_name,
last_name
from
users
left join
companies on companies.id = users.company_id
where (
companies.name like 'TERM%' or
first_name like 'TERM%' or