Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Reinink reinink

View GitHub Profile
@reinink
reinink / toggle.md
Last active Mar 12, 2021
Toggle.md
View toggle.md
// Option 1: Manually
this.$inertia.post(`/toggle-thing/${this.user.id}`, {}, { preserveScroll: true })
<!-- Option 2: Inertia Link -->
<inertia-link :href="`/toggle-thing/${user.id}`" preserve-scroll>Toggle</inertia-link>
@reinink
reinink / AddressInput.vue
Last active Feb 17, 2021
Multiple v-models in Vue 3
View AddressInput.vue
<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'
@reinink
reinink / Model.php
Created Feb 5, 2021
Prevent relationship lazy-loading in Laravel
View Model.php
<?php
namespace App;
use Exception;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Model extends Eloquent
{
public function getRelationshipFromMethod($name)
View InertiaServiceProvider.php
<?php
namespace App\Providers;
use Inertia\ServiceProvider;
use Illuminate\Http\Request;
class InertiaServiceProvider extends ServiceProvider
{
/**
@reinink
reinink / query.sql
Last active Jul 27, 2020
Text search across multiple tables using MySQL
View query.sql
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
View natural_sort.sql
SELECT name
FROM devices
WHERE name IN (
'Apple iPhone 11',
'Apple iPhone 3G',
'Apple iPhone XR'
)
ORDER By name+0<>0 DESC, name+0, name;
View trim_leading_whitespace.php
<?php
function trim_leading_whitespace($code)
{
$lines = collect(explode("\n", $code));
$min = collect(explode("\n", $code))->filter(function ($line) {
return trim($line);
})->min(function ($line) {
return strlen($line) - strlen(ltrim($line));
View nulls_last_tweet.html
<!DOCTYPE html>
<html>
<head>
<title>Nulls Last</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="antialiased leading-none">
<div class="flex w-full p-24 bg-gray-300">
@reinink
reinink / DateInput.vue
Created Aug 27, 2019
Pikaday Vue Component
View DateInput.vue
<template>
<div>
<label v-if="label" class="form-label" :for="`date-input-${_uid}`">{{ label }}:</label>
<input v-bind="$attrs" class="form-input" :id="`date-input-${_uid}`" :class="{ error: error }" type="text" ref="input" :value="value" @change="change" @keyup="change">
<div v-if="error" class="form-error">{{ error }}</div>
</div>
</template>
<script>
import pikaday from 'pikaday'
View order_by_nulls.php
<?php
use Illuminate\Database\Query\Builder;
Builder::macro('orderByNulls', function ($column, $direction = 'asc', $nulls = 'last', $bindings = []) {
$column = $this->getGrammar()->wrap($column);
$direction = strtolower($direction) === 'asc' ? 'asc' : 'desc';
$nulls = strtolower($nulls) === 'first' ? 'NULLS FIRST' : 'NULLS LAST';
return $this->orderByRaw("$column $direction $nulls", $bindings);
});