0

I am using route prefixing and I am coming up with an issue and not sure how to fix it.

First actual question is can I keep my links the same as they were before I added the prefixing?

Previously I had links for example and my routes were like this.

<a href="{{ route('users.edit', $user->id) }}">Edit</a>

Route::resource('users', 'UsersController');

However now I have added in a prefix to a group of routes so that links will show up as mysite.com/backstage/users.

Route::group(array('prefix' => 'backstage'), function()
{
    Route::resource('users', 'UsersController');
});

So now with ALL my views do I have to go through each one and edit all the links so that they look like this or can I do something different so I can handle this situation differently.

<a href="{{ route('backstage.users.edit', $user->id) }}">Edit</a>

I'm also concerned about my breadcrumbs for my application.

<?php

Breadcrumbs::register('users.index', function($breadcrumbs) {
    $breadcrumbs->parent('home');
    $breadcrumbs->push('Users', route('backstage.users.index'));
});

Do I have to include the backstage or can I keep it without?

user3732216
  • 1,579
  • 8
  • 29
  • 54
  • 1
    See http://stackoverflow.com/questions/25290229/laravel-named-route-for-resource-controller for some help/issues with your named routes. – ceejayoz Mar 25 '15 at 18:58
  • I'm wondering if my root issue is my routes file or my breadcrumbs file. How should I deal with this so that I can handle all future changes in one file and it LIMITS future issues from arising. – user3732216 Mar 25 '15 at 19:05
  • 1
    I personally shy away from `Route::resource` in favor of explicitly defining my routes (including any names I might use). – ceejayoz Mar 25 '15 at 19:08
  • If you were able to show me examples in the form of an answer of how you would handle my situation it would go a long way to me understand what I would need to do to correct my mistakes and prevent issues such as this in the future. – user3732216 Mar 25 '15 at 19:09

1 Answers1

1

The only way I know to do it is pass names as a third argument like:

Route::resource('users', 'UsersController',
['names'=>['index'=>'users', 'store'=>'users.store']]);

A lot of people avoid using the resource routing. Phil explains some reasoning here Beware the route to evil. Basically he's saying it can be a nightmare if you, or someone else, comes back to it later to figure out. You often have special cases that you put ahead of the resource so they get hit first in the routing and the whole thing turns into a mess.

Casey
  • 1,941
  • 3
  • 17
  • 30
  • Great but will anything additional need to be done since this is grouped inside of a closure for adding on a prefix to a group? – user3732216 Mar 26 '15 at 02:24
  • @user3732216 no nothing additional. It would be like doing `Route::get('users', ['as'=>'users.index', 'uses'=>'UsersController@index'])` but for each of the resources. So because the route is named it doesn't matter what the URI is – Casey Mar 26 '15 at 10:51