Skip to content

Instantly share code, notes, and snippets.

View jacksleight's full-sized avatar

Jack Sleight jacksleight

View GitHub Profile

See below:

@jacksleight
jacksleight / crud.blade.php
Last active December 2, 2024 11:55
Volt + Flux single file CRUD
<?php
use App\Models\Tag;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Url;
use Livewire\Attributes\Validate;
use Livewire\Volt\Component;
use Livewire\WithPagination;
new class extends Component
Statamic.booting(() => {
Alpine.magic('useField', (el) => {
return () => {
const vm = closestVm(el);
if (!vm) {
return;
}
const data = Alpine.reactive({
value: vm.value,
@jacksleight
jacksleight / rename-package.md
Last active April 27, 2023 07:33
Rename Package

With this method anyone who has the package installed will no longer receive updates and the addon will appear as unlisted in the control panel. The old package will still be installable via composer (GitHub should redirect the old repo URL), however it will output a warning advising the user to switch to the new version.

  1. Disconnect the GitHub repo from Packagist
  2. Rename the GitHub repo
  3. Push an updated composer.json plus anything else that needs renaming
  4. Resubmit the package to Packagist using the new name
  5. Mark the old package as abandoned on Packagist, and use the new name in the form
  6. Update Statamic marketplace with the new GitHub URL and Packagist name
@jacksleight
jacksleight / Divider.php
Created February 22, 2023 09:40
Statamic Divider Fieldtype
<?php
namespace App\Fieldtypes;
use Statamic\Fields\Fieldtype;
class Divider extends Fieldtype
{
}
@jacksleight
jacksleight / AppServiceProvider.php
Last active February 28, 2023 14:39
Convert legacy Bard Text Align mark values to Tiptap 2 text align values
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
---
sorts:
title: Name
price:asc: Price (Low – High)
price:desc: Price (High – Low)
features:
- Glitter
- Lights
- Sparkles
- Wheels
@jacksleight
jacksleight / AppServiceProvider.php
Last active December 16, 2022 11:29
Statamic Computed Value Classes
<?php
Statamic::booted(function () {
foreach (app()['files']->files(app_path('Values')) as $file) {
$class = $file->getBasename('.php');
$fqcn = $this->app->getNamespace()."Values\\{$class}";
if (is_subclass_of($fqcn, Values::class)) {
$object = app($fqcn);
$collections = $fqcn::$collections;
$fields = Arr::except(get_class_methods($object), '__construct');
foreach ($collections as $collection) {
@jacksleight
jacksleight / AppServiceProvider.php
Last active October 27, 2022 15:16
Add entry count to taxonomy term listing
<?php
namespace App\Providers;
use App\Taxonomies\LocalizedTerm;
use Illuminate\Support\ServiceProvider;
use Statamic\Taxonomies\LocalizedTerm as StatamicLocalizedTerm;
class AppServiceProvider extends ServiceProvider
{
@jacksleight
jacksleight / statamic_form.php
Last active August 17, 2022 09:01
`statamic_form()` function for Blade
<?php
use Statamic\Tags\Loader;
use Statamic\View\Antlers\Parser;
if (! function_exists('statamic_form')) {
function statamic_form($handle, $params = [])
{
$form = Form::find($handle);
$html = app(Loader::class)->load('form', [
'parser' => app(Parser::class),