ruudy
ruudy

Reputation: 491

NotFoundHttpException at new route Laravel 4

i see there are similar questions but dont find any clue of me problem.

I created a basic users system, to manage groups, permissions, users, etc. The basic routes like create, edit, delete, index are working.

Now im trying to add one more function to UserController, to manage the users groups in a simple view.

Route::group(array('prefix' => 'admin'), function()
{
    Route::resource('groups', 'GroupController');
    Route::resource('users', 'UserController');
});

The function in controller:

public function groups($id)
{
    $user = Sentry::findUserByID($id);

    $groups = $user->getGroups();

    return View::make('users.show')
        ->with('groups', $groups);
}

And the users/groups.blade.php:

@extends('layouts.admin')

@section('content')
<header id="page-title">
    <h1>User Groups</h1>
</header>

<!-- if there are creation errors, they will show here -->
{{ HTML::ul($errors->all()) }}

{{ Form::open(array('url' => 'admin/users/save_groups')) }}

<div class="form-group">

</div>

{{ Form::submit('Create!', array('class' => 'btn btn-primary')) }}
{{ Form::button('Cancel', array('class' => 'btn btn-danger')) }}

{{ Form::close() }}

@stop

I go to url "mysite/admin/users/2/groups", and im getting the NotFoundHttpException, i try many ways to make it works and dont know what is happening.

I assume it will works like "mysite/admin/users/2/edit", but if i test the show function, it only is "mysite/admin/users/2", dont need the show action to know is that function, maybe i missed something.

Upvotes: 0

Views: 2026

Answers (1)

Glad To Help
Glad To Help

Reputation: 5387

You have declared a route for "GroupsController". As per the documentation, this will only handle actions as defined in the table: "Actions Handled By Resource Controller"

Just by adding one more action it won't simply be extended by Laravel. You should instead type:

Route::get('users/{id}/groups', 'UserController@groups');

Upvotes: 1

Related Questions