kcesys/laravel-inertia-genealogy

Laravel bridge for KCESYS Genealogy library with Inertia support

Installs: 101

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/kcesys/laravel-inertia-genealogy

dev-main 2025-12-15 17:34 UTC

This package is auto-updated.

Last update: 2025-12-15 17:35:57 UTC


README

A Laravel bridge for kcesys/php-genealogy designed for seamless integration with Inertia.js.

Installation

composer require kcesys/laravel-inertia-genealogy

Features

  • Fluent Helper: Genealogy::for($data) wrapper.
  • Inertia Integration: share() method to automatically inject props.
  • Auto-Discovery: Automatically transforms Eloquent Models.

Usage

In your Controller:

use KCESYS\LaravelGenealogy\Genealogy;
use App\Models\User;
use Inertia\Inertia;

public function index()
{
    $family = User::with('parents', 'children')->get();

    // Option 1: Pass as Prop
    return Inertia::render('MyTree', [
        'graph' => Genealogy::for($family)->toGraph([
             'label' => 'full_name', // Map 'label' to 'full_name' attribute
             'spouses' => fn($u) => $u->partners->pluck('id') // Custom relationship mapping
        ])
    ]);
}

Sharing Globally

If you want the genealogy data available on every page (e.g. for a sidebar widget):

// In HandleInertiaRequests Middleware
public function share(Request $request)
{
    return array_merge(parent::share($request), [
        'genealogy' => fn() => Genealogy::for($request->user()->family)->toGraph()
    ]);
}