Skip to content

Instantly share code, notes, and snippets.

@tanthammar
tanthammar / HasLinks.php
Last active July 10, 2020 11:14
Laravel Append Model Links
@tanthammar
tanthammar / validation.php
Created August 21, 2020 18:07
sv/validation.php
<?php
return [
'accepted' => 'Detta alternativ måste accepteras.',
'active_url' => 'Värdet är inte en giltig URL.',
'after' => 'Datumet måste vara efter :date.',
'after_or_equal' => 'Fältet måste vara ett datum efter :date eller lika med :date',
'alpha' => 'Fältet får bara innehålla bokstäver.',
'alpha_dash' => 'Fältet får bara innehålla bokstäver, nummer och bindestreck.',
'alpha_num' => 'Fältet får bara innehålla bokstäver och nummer.',
<?php
/**
* In your Livewire model for the list of items
*/
class ItemList extends Component
{
// rest of component
@tanthammar
tanthammar / HasUuidTrait.php
Last active January 28, 2021 16:47
Laravel Model Uuid trait
<?php
namespace App\Traits;
use Hidehalo\Nanoid\Client;
/**
* Source: https://github.com/jamesmills/eloquent-uuid
* added prefix
* last updated 28 jan 2021.
@tanthammar
tanthammar / AutoGeneratesPosition.php
Last active February 20, 2021 04:17
Auto generate spatial point when creating or updating a Model
<?php
namespace App\Traits;
use App\Helpers\GeoHelper;
use Grimzy\LaravelMysqlSpatial\Types\Point;
trait AutoGeneratesPosition
{
@tanthammar
tanthammar / always-on-top.js
Created May 14, 2021 17:31
JS Get highest z-index, always on top
window.findHighestZ = () => [...document.querySelectorAll('body *')]
.map(elt => parseFloat(getComputedStyle(elt).zIndex))
.reduce((z, highest=Number.MIN_SAFE_INTEGER) =>
isNaN(z) || z < highest ? (isNaN(highest) ? 1 : highest) : z
)
//vanilla
document.getElementById("foo").style.zIndex = window.findHighestZ()
@tanthammar
tanthammar / HasLinks.php
Last active July 5, 2022 18:22
No more controllers! Only Laravel LiveWire routes and a handy Eloquent Model trait.
@tanthammar
tanthammar / LivewireSortable.php
Last active August 9, 2022 20:52
Livewire Sortable fix with array form
<?php
namespace App\Http\Livewire\App\Organizers\Forms;
use App\Http\Livewire\Traits\Form;
use App\Models\Organizer;
use Livewire\Component;
class People extends Component
{
@tanthammar
tanthammar / Media.blade.php
Last active October 19, 2022 00:01
LiveWire Spatie Media Image upload with VueCroppa
<div id="media-comp" class="display-contents">
<media inline-template>
<form>
<div v-for="(image, index) in form" :key="index" @touchstart.stop @mousedown.stop class="col-span-6">
<h3 class="text-3xl font-medium">@{{ image.label }}</h3>
<p class="py-3">Allowed Width @{{image.width}}px, Height @{{image.height}}px, Max file size @{{image.maxFileSize}}</p>
<input v-model="image.value" wire:model="@{{ image.name }}" type="hidden">
<croppa v-model="image.model" :width="image.width" :height="image.height"
:placeholder="locale == 'sv' ? 'Välj en bild' : 'Choose an image'"
:accept="'image/*'" :file-size-limit="image.maxByte" :zoom-speed="3" :disable-drag-and-drop="false"
@tanthammar
tanthammar / ocr.php
Created September 27, 2019 10:38 — forked from AdamGerthel/ocr.php
Generate BankGiro/PlusGiro OCR numbers via PHP
<?php
/**
* OCR Number generation function
*
* @param string $base_number
* The base number that you wish to use for the OCR nr. Can be any number,
* but usually consists of client ID combined with invoice ID or similar.
* @param boolean $length
* Use length if you want the OCR number to add a length