Skip to content

Instantly share code, notes, and snippets.

View ssr765's full-sized avatar
▶️
https://ssr765.github.io/Memory-Game/

Sergi ssr765

▶️
https://ssr765.github.io/Memory-Game/
  • Spain
  • 02:49 (UTC +02:00)
View GitHub Profile
@ssr765
ssr765 / deepWith.d.ts
Created February 13, 2025 20:04
My very first TypeScript complex type. It "loads" relations from models retrieved from a Laravel API making the properties not null. It does recursively, so can work with deep relationships.
export type With<Model, Relation extends string> =
Relation extends `${infer First}.${infer Rest}`
? Omit<Model, First> & {[K in First]: With<NonNullable<Model[First]>, Rest>}
: Relation extends keyof Model
? Omit<Model, Relation> & Required<Pick<Model, Relation>>
: never
@ssr765
ssr765 / MultiModelPagination.php
Last active February 13, 2025 10:13
This is a Laravel trait I created to implement dynamic multi-model pagination. It supports soft deletes and eager loading. I'm looking to improve my Laravel/PHP skills, so feel free to leave any comments or suggestions on how improve it!
<?php
namespace App\Traits;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\DB;
trait MultiModelPagination