PHPackages                             perfect-drive/referable - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. perfect-drive/referable

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

perfect-drive/referable
=======================

Automatically create routes for Models and Enums to make them referable in your Laravel backed SPA frontend

1.3.0(1y ago)1395↓50%[1 PRs](https://github.com/perfect-drive/referable/pulls)MITPHPPHP ^8.2CI passing

Since Mar 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/perfect-drive/referable)[ Packagist](https://packagist.org/packages/perfect-drive/referable)[ Docs](https://github.com/perfect-drive/referable)[ GitHub Sponsors]()[ RSS](/packages/perfect-drive-referable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (12)Versions (6)Used By (0)

Automatically create routes for Models and Enums to make them referable in your SPA frontend
============================================================================================

[](#automatically-create-routes-for-models-and-enums-to-make-them-referable-in-your-spa-frontend)

[![Latest Version on Packagist](https://camo.githubusercontent.com/92278f47a84f79e77726f50c79ab5df6d4e98a900448aa14b2a08db028e71721/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706572666563742d64726976652f726566657261626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/perfect-drive/referable)[![GitHub Tests Action Status](https://camo.githubusercontent.com/51d0d1d112a2cff963e273579b075521d748afd15d0b340969a8f1a263d19ad7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706572666563742d64726976652f726566657261626c652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/perfect-drive/referable/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/7c7f24827136a02fbec317588eb159249cf1123aff383abbfaea3550bd03b8a2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706572666563742d64726976652f726566657261626c652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/perfect-drive/referable/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/4bfa609c73f071855d08c79965117a14a3b6149d90590da9bbfc0774dabc4cfc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706572666563742d64726976652f726566657261626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/perfect-drive/referable)

To populate drowdowns (or other ways of reference) in an SPA form a separate endpoint can be used to create the array of name/value pairs. This package allows you to automatically create routes for your Models and Enums to make them referable in your Laravel backed SPA frontend.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require perfect-drive/referable
```

You can publish the config file with:

```
php artisan vendor:publish --tag="referable-config"
```

This is the contents of the published config file:

```
return [
    /*
     * The directories to search for Referable classes.
     */
    'directories' => [
        app_path('Enums'),
        app_path('Models'),
    ],

    /*
     * The middleware array to use for the Referable routes.
     */
    'middleware' => ['api', 'auth:sanctum'],

    /*
     * The key name to use for the referable key in the json response.
     */
    'key_name' => 'value',

    /*
     * The value name to use for the referable value in the json response.
     */
    'value_name' => 'title',

    /*
     * The base url for the referable routes.
     */
    'base_url' => 'spa/referable/',
];
```

Usage
-----

[](#usage)

### On a Model:

[](#on-a-model)

```
