Skip to content

Instantly share code, notes, and snippets.

View neverything's full-sized avatar
🍀
Good vibes for you

Silvan Hagen neverything

🍀
Good vibes for you
View GitHub Profile
<?php
namespace OllieChild;
function enqueue_custom_child_block_styles() {
// Scan our styles folder to locate block styles.
$files = glob( get_stylesheet_directory() . '/assets/blocks/*.css' );
foreach ( $files as $file ) {
@neverything
neverything / HasTenantAwareSessionKeys.php
Last active March 17, 2025 06:03
Filament persist table filters, sort and search per tenant: https://silvanhagen.com/writing/filament-persist-filters-tenant/
<?php
namespace App\Filament\Traits;
use Filament\Facades\Filament;
trait HasTenantAwareSessionKeys
{
public function getTableFiltersSessionKey(): string
{
@neverything
neverything / CopyToS3Command.php
Created February 25, 2025 10:35
A Laravel artisan command to migrate files from one disk to another for example to move to S3-compatible object storage and back. See https://silvanhagen.com/talks/meetup-laravel-cloud/
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
class CopyToS3Command extends Command
{
protected $signature = 'storage:mirror
@neverything
neverything / MigrateDatabaseCommand.php
Created February 25, 2025 06:13
A Laravel artisan command to migrate database tables from MySQL to Postgres and back. See https://silvanhagen.com/talks/meetup-laravel-cloud/
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Symfony\Component\Console\Helper\ProgressBar;
@neverything
neverything / UpdateMediaInfoCommand.php
Created October 18, 2024 09:02
Set Image and Video dimension for the Spatie Laravel Media Library as custom properties: https://silvanhagen.com/writing/image-and-video-dimensions-laravel-media-library
<?php
namespace App\Console\Commands;
use App\Actions\Media\UpdateMediaInfoAction;
use Illuminate\Console\Command;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
class UpdateMediaInfoCommand extends Command
{
@neverything
neverything / UpdateMediaInfoJob.php
Created October 18, 2024 08:17
Set Image and Video dimension for the Spatie Laravel Media Library as custom properties: https://silvanhagen.com/writing/image-and-video-dimensions-laravel-media-library
<?php
namespace App\Jobs;
use App\Actions\Media\UpdateMediaInfoAction;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\Attributes\DeleteWhenMissingModels;
use Illuminate\Queue\InteractsWithQueue;
@neverything
neverything / UpdateMediaInfoAction.php
Last active October 18, 2024 08:04
Set Image and Video dimension for the Spatie Laravel Media Library as custom properties: https://silvanhagen.com/writing/image-and-video-dimensions-laravel-media-library
<?php
namespace App\Actions\Media;
use Exception;
use FFMpeg\FFProbe;
use Illuminate\Support\Facades\Log;
use Spatie\Image\Image;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
@neverything
neverything / MediaObserver.php
Last active October 18, 2024 06:22
Set Image and Video dimension for the Spatie Laravel Media Library as custom properties: https://silvanhagen.com/writing/image-and-video-dimensions-laravel-media-library
<?php
namespace App\Observers;
use App\Actions\Media\UpdateMediaInfoAction;
use App\Jobs\UpdateMediaInfoJob;
use Illuminate\Support\Facades\Log;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
class MediaObserver
@neverything
neverything / LinkResource.php
Created August 27, 2024 07:50
Background File Uploads using Filament Forms, FilePond, Livewire and Alpine.js: https://silvanhagen.com/writing/background-file-upload-in-filament-forms
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\LinkResource\Pages;
use App\Models\Link;
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Forms\Set;
@neverything
neverything / functions.php
Last active August 13, 2024 14:14
Conditionally Redirect in WordPress with full knowledge of the queried content: https://silvanhagen.com/writing/conditionally-redirect-in-wordpress/
<?php
/**
* Redirect job ads to their parent page if they are not published.
*
* @link https://developer.wordpress.org/reference/hooks/template_redirect/
* @link https://developer.wordpress.org/reference/functions/is_404/
* @link https://developer.wordpress.org/reference/functions/get_queried_object_id/
* @link https://developer.wordpress.org/reference/functions/get_post_meta/
* @link https://developer.wordpress.org/reference/functions/get_post_status/
* @link https://developer.wordpress.org/reference/functions/wp_get_post_parent_id/