PHPackages                             api-skeletons/laravel-hal - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. api-skeletons/laravel-hal

ActiveLibrary[API Development](/categories/api)

api-skeletons/laravel-hal
=========================

Hypertext Application Language for Laravel

5.0.2(4y ago)54.3k3[2 PRs](https://github.com/API-Skeletons/laravel-hal/pulls)1MITPHPPHP ^8.0

Since Jan 4Pushed 2y ago1 watchersCompare

[ Source](https://github.com/API-Skeletons/laravel-hal)[ Packagist](https://packagist.org/packages/api-skeletons/laravel-hal)[ RSS](/packages/api-skeletons-laravel-hal/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (15)Used By (1)

Hypertext Application Language for Laravel
==========================================

[](#hypertext-application-language-for-laravel)

[![Build Status](https://github.com/API-Skeletons/laravel-hal/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/API-Skeletons/laravel-hal/actions/workflows/continuous-integration.yml?query=branch%3Amain)[![Code Coverage](https://camo.githubusercontent.com/d10745c75c604c39450ec70ac2cc2a405adfe73bdca2d37adc9e44a878f9bbe3/68747470733a2f2f636f6465636f762e696f2f67682f4150492d536b656c65746f6e732f6c61726176656c2d68616c2f6272616e63682f6d61696e2f6772617068732f62616467652e737667)](https://codecov.io/gh/API-Skeletons/laravel-hal/branch/main)[![Documentation Status](https://camo.githubusercontent.com/2fb6ba5792f6a9faa0d5a2c9021b2dc51d0f97c3798242ce730bcf83936ccff0/68747470733a2f2f72656164746865646f63732e6f72672f70726f6a656374732f6170692d736b656c65746f6e732d6c61726176656c2d68616c2f62616467652f3f76657273696f6e3d6c6174657374)](https://api-skeletons-laravel-hal.readthedocs.io/en/latest/?badge=latest)[![PHP Version](https://camo.githubusercontent.com/d43f3018edfd35e43d9669f893ce52781d51f11ac9240420a3dce982b6ae8af1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e302532622d626c7565)](https://img.shields.io/badge/PHP-7.3%20to%208.0%2b-blue)[![Laravel Version](https://camo.githubusercontent.com/7330d8a5139fa5b0654b55716554c94de722670528ade3db570ad7e3e09c3156/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d382e782532622d726564)](https://img.shields.io/badge/Laravel-5.7%20to%208.x-red)[![Total Downloads](https://camo.githubusercontent.com/1d36a743685d9c7d890032e8db3dfc1250dad9ff0fd12e0c4afd44f480b5a85b/68747470733a2f2f706f7365722e707567782e6f72672f6170692d736b656c65746f6e732f6c61726176656c2d68616c2f646f776e6c6f616473)](//packagist.org/packages/api-skeletons/laravel-hal)[![License](https://camo.githubusercontent.com/ce9ab2ce6b2b5c9261ed2945e3fdc43251e6bfd2528537c962862f620eeb276f/68747470733a2f2f706f7365722e707567782e6f72672f6170692d736b656c65746f6e732f6c61726176656c2d68616c2f6c6963656e7365)](//packagist.org/packages/api-skeletons/laravel-hal)

HAL - Hypertext Application Language is a JSON dialect which gives a consistent and easy way to add HATEOAS - Hypertext As The Engine Of Application State - to your API. This library makes composing HAL responses easy including embedded data.

This library consists of a Hydrator Manager and you will write hydrators for the classes you want to serve as HAL. Central to this library is a Resource object on which HAL resources are attached.

Although this library is for Laravel, it is **not** specific to Eloquent. This same library can be used with any datasource to compose a HAL response.

This is a direct implementation of

### [Read The Documentation](https://api-skeletons-laravel-hal.readthedocs.io/en/latest/index.html)

[](#read-the-documentation)

Quick Look
----------

[](#quick-look)

```
  return $this->hydratorManager->resource($data)
      ->addLink('self', route('routeName::fetch', $class->id))
      ->addEmbeddedResource('example', $class->example)
      ->toArray();
```

Quick Start
-----------

[](#quick-start)

- Create a hydrator manager
- Create a hydrator for the User class
- Create a hydrator for the Role class
- Compose these into a HAL resource and return HAL from a controller action

### Create a hydrator manager

[](#create-a-hydrator-manager)

```
namespace App\HAL;

use ApiSkeletons\Laravel\HAL\HydratorManager as HALHydratorManager;

final class HydratorManager extends HALHydratorManager
{
    public function __construct()
    {
        $this->classHydrators = [
            \App\Models\Role::class => \App\HAL\Hydrator\RoleHydrator::class,
            \App\Models\User::class => \App\HAL\Hydrator\UserHydrator::class,
        ];
    }
```

### Create a hydrator for the User class

[](#create-a-hydrator-for-the-user-class)

```
namespace App\HAL\Hydrator;

use ApiSkeletons\Laravel\HAL\Hydrator;
use ApiSkeletons\Laravel\HAL\Resource;
use App\Models\User;

final class UserHydrator extends Hydrator
{
    public function extract($class): Resource
    {
        $data = [];

        $fields = [
            'id',
            'name',
            'email',
        ];

        // Extract fields into an array to be used by the resource
        foreach ($fields as $field) {
            $data[$field] = $class->$field;
        }

        // Create a new resource and assign self link and extract the
        // roles into an embedded resource.  Note `addEmbeddedResources`
        // is used for arrays and `addEmbeddedResource` is used for classes
        return $this->hydratorManager->resource($data)
            ->addLink('self', route('hal/user::fetch', $class->id))
            ->addEmbeddedResources('roles', $class->roles)
            ;
    }
}
```

### Create a hydrator for the Role class

[](#create-a-hydrator-for-the-role-class)

```
namespace App\HAL\Hydrator;

use ApiSkeletons\Laravel\HAL\Hydrator;
use ApiSkeletons\Laravel\HAL\Resource;
use App\Models\Role;

final class RoleHydrator extends Hydrator
{
    public function extract($class): Resource
    {
        $data = [];

        $fields = [
            'id',
            'name',
            'guard_name',
        ];

        // Extract fields into an array to be used by the resource
        foreach ($fields as $field) {
            $data[$field] = $class->$field;
        }

        // Create a new resource and assign self link and extract the
        // roles into an embedded resource.  Note `addEmbeddedResources`
        // is used for arrays and `addEmbeddedResource` is used for classes
        return $this->hydratorManager->resource($data)
            ->addLink('self', route('hal/role::fetch', $class->id))
            ;
    }
}
```

### Compose these into a HAL resource and return HAL from a controller action

[](#compose-these-into-a-hal-resource-and-return-hal-from-a-controller-action)

```
public function fetch(User $user, Request $request)
{
    $hydratorManager = new \App\HAL\HydratorManager();
    return $hydratorManager->extract($user)->toArray();
}
```

### HAL Response

[](#hal-response)

```
{
  "_links":{
    "self":{
      "href":"https://apiskeletons.com/user/1"
    }
  },
  "id":1,
  "name":"Tom H Anderson",
  "email":"tom.h.anderson@gmail.com",
  "_embedded":{
    "roles":[
      {
        "_links":{
          "self":{
            "href":"https://apiskeletons.com/role/1"
          }
        },
        "id":1,
        "name":"admin",
        "guard_name":"web",
      }
    ]
  }
}
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~30 days

Recently: every ~3 days

Total

14

Last Release

1558d ago

Major Versions

0.9.0 → 1.0.02021-01-04

1.0.1 → 2.0.02021-01-05

2.0.0 → 3.0.02021-01-08

3.0.4 → 4.0.02022-01-19

4.0.1 → 5.0.02022-01-30

PHP version history (3 changes)2.0.0PHP ^7.4 || ^8.0

3.0.1PHP ^7.3 || ^8.0

4.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/49dd7d9dba889ac674b0da447d9c1e69d1128dc3ccbaef98ba83d6ee519fc2d6?d=identicon)[tom\_anderson](/maintainers/tom_anderson)

---

Top Contributors

[![TomHAnderson](https://avatars.githubusercontent.com/u/493920?v=4)](https://github.com/TomHAnderson "TomHAnderson (90 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/api-skeletons-laravel-hal/health.svg)

```
[![Health](https://phpackages.com/badges/api-skeletons-laravel-hal/health.svg)](https://phpackages.com/packages/api-skeletons-laravel-hal)
```

###  Alternatives

[statamic/cms

The Statamic CMS Core Package

4.8k3.2M720](/packages/statamic-cms)[team-reflex/discord-php

An unofficial API to interact with the voice and text service Discord.

1.1k379.4k24](/packages/team-reflex-discord-php)[spinen/laravel-clickup

SPINEN's Laravel Package for ClickUp.

282.2k](/packages/spinen-laravel-clickup)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
