0

Page not found all I get when trying to get these pages.

web.php looks like this

Route::resource('admin/roles', 'RoleController');

route:list look like this

| GET|HEAD  | admin/roles         | index   | App\Http\Controllers\RoleController@index   
| GET|HEAD  | admin/roles/create  | create  | App\Http\Controllers\RoleController@create  
| PUT|PATCH | admin/roles/{}      | update  | App\Http\Controllers\RoleController@update  
| GET|HEAD  | admin/roles/{}      | show    | App\Http\Controllers\RoleController@show    
| DELETE    | admin/roles/{}      | destroy | App\Http\Controllers\RoleController@destroy 
| GET|HEAD  | admin/roles/{}/edit | edit    | App\Http\Controllers\RoleController@edit    

Controllerlook like this

public function show($id)
{
    $role = Role::find($id);
    return view('admin.roles/show')->with('role',$role);
}

public function edit($id)
{
    $role = Role::find($id);
    return view('admin.roles.edit')->with('role',$role);
}

enter image description here

Harry
  • 2,429
  • 4
  • 21
  • 26
  • I think there's something messed up with your `route:list`, since you have routes like `admin/roles/{}`. It should contain `{role}` instead of `{}` also the name should be `roles.index` etc, but then you load view `admin.roles/show`... – Harry Oct 02 '18 at 14:43

1 Answers1

0

You should try navigating your browser to admin/roles/1 instead of admin/roles/show/1. The route you've tried doesn't exist so you're correctly getting a 404 error.

Since the create and index page work fine, but not show I think there is something up with the route bindings.

Since the routes in route:list command show admin/roles/{}, it makes me think laravel couldn't figure out the bindings.

My best guess for this it to check the http kernel. You should have the \Illuminate\Routing\Middleware\SubstituteBindings::class middleware either in the $middleware array or inside the web group under the $middlewareGroups array. I suggest putting it in the web middleware group.

eg:

protected $middlewareGroups = [

    //

    'web' => [
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ],

    //
];

Another suggestion:

Try defining the routes individually instead of using Route::resource()

Route::get('admin/roles', 'RoleController@index');
Route::get('admin/roles/create', 'RoleController@create');
Route::patch('admin/roles/{role}', 'RoleController@update');
Route::get('admin/roles/{role}', 'RoleController@show');
Route::delete('admin/roles/{role}', 'RoleController@delete');
Route::get('admin/roles/{role}/edit', 'RoleController@edit');

Note you may need to add ->name('some-name') to fix the names

Harry
  • 2,429
  • 4
  • 21
  • 26
  • Get page not found with this also. example.test/admin/roles/create works. –  Oct 02 '18 at 13:44
  • index page also works. Thanks for editing my post btw. –  Oct 02 '18 at 13:58
  • I think the clue is in the fact that index and create both work, and your `route:list` returns `admin/roles/{}` routes, instead of `admin/roles/{role}`. I've edited my answer with another suggestion – Harry Oct 02 '18 at 14:50
  • With your second suggestion show page works, but edit page still not work. Missing required parameters for [Route: ] [URI: admin/roles/{role}] resources\views\admin\roles\edit.blade.php –  Oct 02 '18 at 15:40
  • SubstituteBindings are both in middlewareGroups and routeMiddleware. –  Oct 02 '18 at 16:08
  • It's working now. It was something with my edit.blade.php page. I had form action="{{action('RoleController@update')". It should be action="{{action('RoleController@update , $role->id')" –  Oct 02 '18 at 16:24