Skip to content

Instantly share code, notes, and snippets.

View reinink's full-sized avatar

Jonathan Reinink reinink

View GitHub Profile
@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 / 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 &&
<?php
use getID3;
$id3 = (new getID3())->analyze(Request::file('file')->getPathname());
$duration = isset($id3['playtime_string']) ? str_pad($id3['playtime_string'], 8, '00:00:00', STR_PAD_LEFT) : null;
<template>
<inertia-head>
<title v-if="title">{{ title }} - My App</title>
<title v-else>My App</title>
<slot />
</inertia-head>
</template>
<script>
export default {
@reinink
reinink / Model.php
Created April 20, 2021 18:55
Laravel - Recently Created
<?php
namespace App\Models;
use Illuminate\Support\Facades\Session;
use Illuminate\Database\Eloquent\Model as Eloquent;
abstract class Model extends Eloquent
{
protected $guarded = [];
@reinink
reinink / toggle.md
Last active March 12, 2021 14:53
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 February 17, 2021 14:03
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'
@reinink
reinink / Model.php
Created February 5, 2021 15:18
Prevent relationship lazy-loading in Laravel
<?php
namespace App;
use Exception;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Model extends Eloquent
{
public function getRelationshipFromMethod($name)
<?php
namespace App\Providers;
use Inertia\ServiceProvider;
use Illuminate\Http\Request;
class InertiaServiceProvider extends ServiceProvider
{
/**