PHPackages                             ysocode/plum - 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. ysocode/plum

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

ysocode/plum
============

Use your Laravel named routes in JavaScript.

v1.1.5(1y ago)082MITJavaScriptPHP ^8.3

Since Dec 31Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/ysocode/plum)[ Packagist](https://packagist.org/packages/ysocode/plum)[ Docs](https://github.com/ysocode/plum)[ RSS](/packages/ysocode-plum/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (8)Used By (0)

Plum – Use Your Laravel Routes in JavaScript
============================================

[](#plum--use-your-laravel-routes-in-javascript)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e7494ed2fbe4108d1946cfe417ac1f19e15385c018c058bc256345a5156aab19/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f79736f636f64652f706c756d2e7376673f7374796c653d666c6174)](https://packagist.org/packages/ysocode/plum)[![Downloads on Packagist](https://camo.githubusercontent.com/61aebec4c7cbd87139234d529951c492b9031af69f4a514872300f0511e76e5d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f79736f636f64652f706c756d2e7376673f7374796c653d666c6174)](https://packagist.org/packages/ysocode/plum)[![License](https://camo.githubusercontent.com/ecc952464f25f0e7cfbf082041c9f0dde054ac080fa490c34bbc9b67e3ee8fd2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f79736f636f64652f706c756d)](https://packagist.org/packages/ysocode/plum)

Introduction
------------

[](#introduction)

Plum provides a JavaScript `route()` function that works like Laravel's, making it a breeze to use your named Laravel routes in JavaScript.

#### Inspiration

[](#inspiration)

Plum is inspired by and derived from Ziggy, created by Jacob Baker-Kretzmar. For more information, check out the [Ziggy repository](https://github.com/tighten/ziggy).

Official Documentation
----------------------

[](#official-documentation)

##### Install Plum using Composer:

[](#install-plum-using-composer)

```
composer require ysocode/plum
```

##### Defining routes

[](#defining-routes)

To define routes, you can follow the [Laravel documentation](https://laravel.com/docs/11.x/routing). Here’s an example of how to define a resource route for "contacts":

```
Route::resource('contacts', ContactController::class);
```

##### Using the `route()` method provided by Plum

[](#using-the-route-method-provided-by-plum)

The route function generates a URL for a given named route:

```
route('contacts.index'); // https://plum.test/contacts
```

##### Using route parameters

[](#using-route-parameters)

For example, you may need to capture a user's ID from the URL. You may do so by defining route parameters:

```
Route::get('/users/{user}', UserController::class)->name('users.show');
```

The route function generates a URL for a given named route with the given parameters:

```
route('users.show', {user: 8847}); // https://plum.test/users/8847
```

Plum generates the final result using the JavaScript URL object, so if a route parameter does not have a [default value](#using-default-parameter-values) and is not provided through the `route()` method, you may end up getting an unexpected result, such as `https://plum.test/users/%7Buser%7D`.

##### Using route multiple parameters

[](#using-route-multiple-parameters)

You may want to capture multiple route parameters, in this case, we capture both the user ID and the profile type:

```
Route::get('/users/{user}/profiles/{profile}', UserProfileController::class)->name('users.profiles.show');
```

The route function can be used to generate the URL for this route with the necessary parameters:

```
route('users.profiles.show', {user: 8847, profile: 'admin'}); // https://plum.test/users/8847/profiles/admin
```

##### Using query parameters

[](#using-query-parameters)

You may want to use query parameters:

```
Route::get('/search', SearchController::class)->name('search');
```

You can pass query parameters by using the `_query` attribute:

```
route('search', {_query: {term: 'Laravel', page: 2}}); // https://plum.test/search?term=Laravel&page=2
```

It’s important to note that if you pass normal parameters that don’t match any defined route parameters, those parameters will automatically become query parameters.

In this case, you can omit the \_query attribute because the search.index route doesn’t require any route parameters. Any parameters passed will automatically be treated as query parameters:

```
route('search', {term: 'Laravel', page: 2}); // https://plum.test/search?term=Laravel&page=2
```

Like Laravel, Plum automatically encodes boolean query parameters as integers in the query string:

```
route('users.show', {user: 8847, active: true}); // https://plum.test/users/8847?active=1
```

##### Using default parameter values

[](#using-default-parameter-values)

Plum supports default route parameter values. To better understand how default parameter values work, you can take a look at the [Laravel documentation](https://laravel.com/docs/urls#default-values).

Now that you know how to define default parameter values, you can use the `route()` function to generate URLs without worrying about parameters that have default values.

```
route('posts.index'); // https://plum.test/en/posts
```

##### Some other useful methods

[](#some-other-useful-methods)

Calling the `route()` method without arguments allows you to use other methods provided by the Router class.

###### Has method

[](#has-method)

You can check if a route exists before using it:

```
if (route().has('posts.index')) {
    const postRoute = route('posts.index'); // https://plum.test/en/posts
}
```

##### Using route model binding

[](#using-route-model-binding)

Plum supports route model binding. To better understand how route model binding work, you can take a look at the [Laravel documentation](https://laravel.com/docs/11.x/routing#route-model-binding).

You can use explicit model binding:

```
use App\Models\Post;

Route::get('/posts/{post:slug}', function (Post $post) {
    return $post;
})->name('posts.show');
```

Alternatively, you can make model binding always use a database column other than id, by defining the route key name:

```
/**
 * Get the route key for the model.
 */
public function getRouteKeyName(): string
{
    return 'slug';
}
```

Now that you know how to use route model binding, you can use the `route()` function to generate URLs by passing the entire object. Plum will automatically resolve the URL using the model's slug as the route model binding key:

```
const post = {
    id: 8847,
    slug: 'how-to-use-plum'
};

route('posts.show', {post: post}); // https://plum.test/posts/how-to-use-plum
```

##### Importing Plum in your Vue app

[](#importing-plum-in-your-vue-app)

Plum includes a Vue plugin to make it easy to use the `route()` helper throughout your Vue app:

```
import {createApp} from 'vue';
import {PlumVue} from '../../vendor/ysocode/plum';
import App from './App.vue';

createApp(App).use(PlumVue);
```

Now you can use the `route()` function anywhere in your Vue components and templates:

```
Home
```

With &lt;script setup&gt; in Vue 3 you can use inject to make the `route()` function available in your component script:

```

    import {inject} from 'vue';

    const route = inject('route');

```

License
-------

[](#license)

Plum is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance63

Regular maintenance activity

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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 ~55 days

Recently: every ~87 days

Total

8

Last Release

118d ago

PHP version history (2 changes)v1.0.0PHP ^8.4

v1.1.2PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/4e4325449b57dd853dad51970b7d9125c9a6942c4e121ed0bd4b1ea10ae93c63?d=identicon)[YuriSalesdeOliveira](/maintainers/YuriSalesdeOliveira)

![](https://www.gravatar.com/avatar/a186bb75f7d3e0d634cd5f1e3f59a8bcf3c08523b8805ed5952ee0358219f7d5?d=identicon)[ysocode](/maintainers/ysocode)

---

Top Contributors

[![yusadeol](https://avatars.githubusercontent.com/u/54549125?v=4)](https://github.com/yusadeol "yusadeol (29 commits)")

---

Tags

laravelroutesplum

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/ysocode-plum/health.svg)

```
[![Health](https://phpackages.com/badges/ysocode-plum/health.svg)](https://phpackages.com/packages/ysocode-plum)
```

###  Alternatives

[tightenco/ziggy

Use your Laravel named routes in JavaScript.

4.3k41.6M267](/packages/tightenco-ziggy)[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4205.3M84](/packages/livewire-volt)[sbine/route-viewer

A Laravel Nova tool to view your registered routes.

57215.9k](/packages/sbine-route-viewer)[proai/lumen-annotations

Route and event binding annotations for Laravel Lumen

1012.4k](/packages/proai-lumen-annotations)

PHPackages © 2026

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