Skip to content

Instantly share code, notes, and snippets.

View reinink's full-sized avatar

Jonathan Reinink reinink

View GitHub Profile
@reinink
reinink / query.sql
Last active November 14, 2023 11:08
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
@reinink
reinink / AppServiceProvider.php
Last active October 22, 2023 13:06
Multi-page Vue App in Laravel
<?php
namespace App\Providers;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use Illuminate\View\Factory as ViewFactory;
class AppServiceProvider extends ServiceProvider
{
@reinink
reinink / app.js
Created November 2, 2018 12:56
Auto register Vue components
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
require('./bootstrap');
window.Vue = require('vue');
@reinink
reinink / gist:1467201
Created December 12, 2011 13:41
Example of how to parse HTML document with phpQuery
<?php
// Include the phpQuery library
// Download at http://code.google.com/p/phpquery/
include 'phpQuery.php';
// Load Mike Fisher's player page on thescore.com
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.thescore.com/nhl/player_profiles/859-mike-fisher');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@reinink
reinink / DateInput.vue
Created August 27, 2019 11:51
Pikaday Vue Component
<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'
@reinink
reinink / ssr.js
Last active November 12, 2022 18:44
Inertia and Vite SSR setup
import { createSSRApp, h } from 'vue'
import { renderToString } from '@vue/server-renderer'
import { createInertiaApp } from '@inertiajs/inertia-vue3'
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import createServer from '@inertiajs/server'
createServer(page =>
createInertiaApp({
page,
render: renderToString,
<?php
TestResponse::macro('inertiaSnapshot', function (...$keys) {
$convertPlainValueToCode = function ($value) {
if ($value === null) {
return 'null';
} elseif (is_bool($value)) {
return $value ? 'true' : 'false';
} elseif (is_string($value)) {
return "'".addslashes($value)."'";
@reinink
reinink / AppServiceProvider.php
Created July 20, 2017 17:04
Eloquent addSubSelect()
<?php
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Database\Query\Expression;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function boot()
@reinink
reinink / inertia-attribute.js
Last active June 14, 2022 03:29
Global Inertia.js click event handler
import { Inertia } from '@inertiajs/inertia'
document.addEventListener('click', (event) => {
if (
event.target.tagName.toLowerCase() === 'a' &&
event.target.hasAttribute('inertia') &&
!event.target.isContentEditable &&
!event.defaultPrevented &&
!event.shiftKey &&
!event.ctrlKey &&
@reinink
reinink / query.php
Created May 20, 2019 12:28
Getting table totals using Laravel Eloquent
<?php
$totals = DB::table('subscribers')
->addSelect(DB::raw('count(*) as all'))
->addSelect(DB::raw("sum(case when status = 'confirmed' then 1 else 0 end) as confirmed"))
->addSelect(DB::raw("sum(case when status = 'unconfirmed' then 1 else 0 end) as unconfirmed"))
->addSelect(DB::raw("sum(case when status = 'cancelled' then 1 else 0 end) as cancelled"))
->addSelect(DB::raw("sum(case when status = 'bounced' then 1 else 0 end) as bounced"))
->addSelect(DB::raw("sum(case when status = 'inactive' then 1 else 0 end) as inactive"))
->get();