npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@salvobee/laravel-resource-route

v1.0.1

Published

Resolve Laravel-style resource route names (photos.index, photos.show, ...) to URLs with optional nesting and query strings.

Readme

Laravel Resource Route

A tiny TypeScript utility that resolves Laravel resource route names to paths, with optional nested prefixes and querystring handling.

⚠️ Important

This resolver is strictly based on Laravel’s default resource route conventions.
It does not support custom or renamed routes.

In other words, it only works correctly if your backend defines routes using the standard Route::resource() or Route::apiResource() helpers, which automatically generate the following names and URI patterns:

| Verb | URI | Action | Route Name | |------|-----|---------|-------------| | GET | /photos | index | photos.index | | GET | /photos/create | create | photos.create | | POST | /photos | store | photos.store | | GET | /photos/{photo} | show | photos.show | | GET | /photos/{photo}/edit | edit | photos.edit | | PUT/PATCH | /photos/{photo} | update | photos.update | | DELETE | /photos/{photo} | destroy | photos.destroy |

If your Laravel routes use different names or structures
for example:

Route::get('/pictures/{id}', 'PhotoController@show')->name('photos.display');

then this resolver cannot infer the correct path from the route name alone, because it assumes the standard {resource}.{action} pattern (e.g. photos.show/photos/{photo}).

This design keeps the resolver lightweight, predictable, and framework-agnostic — it’s meant as a simple fallback for projects that already follow Laravel’s default resource routing style.

Install

npm i @salvobee/laravel-resource-route
# or
yarn add @salvobee/laravel-resource-route
# or
pnpm add @salvobee/laravel-resource-route

Quick start (TypeScript)

import { createLaravelResourceResolver } from "@salvobee/laravel-resource-route";

const route = createLaravelResourceResolver("photos");

// "/photos"
route("photos.index");

// "/photos/create"
route("photos.create");

// "/photos/42"
route("photos.show", { photo: 42 });
// also works with fallback key "id":
route("photos.show", { id: 42 });

// "/photos/42/edit"
route("photos.edit", { photo: 42 });

With nested prefixes

const nested = createLaravelResourceResolver("photos", {
    prefix: "/users/{user}",
});
// "/users/7/photos/42"
nested("photos.show", { user: 7, photo: 42 });

Placeholders in the prefix (e.g., {user}) are replaced from params. Any extra params not used in the path will be appended as a querystring.

Base URL & trailing slash

const apiRoute = createLaravelResourceResolver("photos", {
  baseUrl: "https://api.example.com",
  trailingSlash: true,
});
// "https://api.example.com/photos/"
apiRoute("photos.index");

HTTP method helper

import { methodForAction } from "@salvobee/laravel-resource-route";

methodForAction("index");  // "GET"
methodForAction("store");  // "POST"
methodForAction("update"); // "PUT" (Laravel accepts PUT or PATCH)

JavaScript usage (CJS)

const {
  createLaravelResourceResolver,
  methodForAction,
} = require("@salvobee/laravel-resource-route");

const route = createLaravelResourceResolver("photos");
console.log(route("photos.show", { id: 99 })); // "/photos/99"

Typing notes

  • If you pass resourceParam, that exact key is required for ID-bound actions (show, edit, update, destroy); otherwise the resolver falls back to a minimal singularization of the resource name (e.g., "photos" -> "photo"), with id as a second fallback key.
  • Arrays in extra params become key[]=v1&key[]=v2 in the querystring.

License

MIT © Salvo Bee