PHPackages                             paulhenri-l/laravel-route-helpers - 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. paulhenri-l/laravel-route-helpers

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

paulhenri-l/laravel-route-helpers
=================================

Rails like route helpers to easily generate paths to your laravel controllers

2.0.0(5y ago)910MITPHPPHP ^7.3CI failing

Since Dec 27Pushed 5y agoCompare

[ Source](https://github.com/paulhenri-l/laravel-route-helpers)[ Packagist](https://packagist.org/packages/paulhenri-l/laravel-route-helpers)[ RSS](/packages/paulhenri-l-laravel-route-helpers/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (3)Dependencies (3)Versions (5)Used By (0)

Laravel route helpers
=====================

[](#laravel-route-helpers)

[![Build Status](https://camo.githubusercontent.com/3668e9416aa04d0492cf8859727d2a9b222e4718e4cfed998b38a73bc0dea57a/68747470733a2f2f7472617669732d63692e6f72672f7061756c68656e72692d6c2f6c61726176656c2d726f7574652d68656c706572732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/paulhenri-l/laravel-route-helpers)

Route helpers are simple function that will generate paths to your application resources.

For instance if you have a `PostsController` you'll get these helpers:

- `posts_path()`
- `post_path()`
- `new_post_path()`
- `edit_post_path()`

Which can in turn be used in your views/app like so:

```
Posts
Got to the post creation form
Show the given post
Edit the given post

```

```
redirect()->to(posts_path()); // Redirect to posts.index
```

The end goal is to leverage autocompletion in order to rapidly create path to our resources while not having to remember the exact route name.

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

[](#installation)

You can install this package using composer

```
composer require paulhenri-l/laravel-route-helpers
```

Usage
-----

[](#usage)

Register your routes just as usual but give them names. On the next application boot the helpers will be generated and loaded.

Your route names should be one of the 7 restful names used by laravel (\*.index, \*.create, \*.store, \*.show, \*.edit, \*.update and \*.destroy)

*Your route names should only contain alpha numeric characters, dots and underscores any route that does not comply to this pattern will not get helpers generated for it.*

```
Route::resource('comments', 'CommentsController');
```

This will generate these helpers:

```
comments_path();
comment_path();
create_comment_path();
edit_comment_path();
```

### Nested resources

[](#nested-resources)

If you are nesting your resources the generated helpers will keep the nesting.

```
Route::resource('posts.comments', 'PostsCommentsController');
```

```
post_comments_path();
post_comment_path();
create_post_comment_path();
edit_post_comment_path();
```

### Irregular names

[](#irregular-names)

If you are using irregular names for your resources, the correct singular form will be used for the helpers.

```
Route::resource('people', 'PeopleController');
```

```
people_path();
person_path();
create_person_path();
edit_person_path();
```

If this tool cannot guess the correct singular form for your route name you'll have to configure it:

### Singular resources

[](#singular-resources)

If you have singular resources you cannot use the index function as it would create conflicts between the plural and singular helpers.

```
Route::resource('account', 'AccountController')->except('index');
```

### Helpers works just like the route function

[](#helpers-works-just-like-the-route-function)

```
