0
votes

I'm having the issue when loading the /usarios/create (/user/create) and being return an error of:

BadMethodCallException

Method App\Http\Controllers\UserController::create does not exist.

Route web file:

Auth::routes();
Route::get('/', 'HomeController@index')->name('home');
Route::resource('usuarios', 'UserController@index');

UserController:

<?php
namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

class UserController extends Controller
{

public function index()
{
    $users = User::all( );
    return view( 'usuarios.index', ['users' => $users]);
}
}

function create()
{
    return view ('usuarios.create');
}

function store(Request $request)
{        
}

function show($id)
{        
}

function edit($id)
{    
}

function update(Request $request, $id)
{        
}

function destroy($id)
{        
}

My version Laravel is 6.0

Any help? Thanks!

2
Remove @index from your resource route. Resource routes only need the controller name.aynber
Sorry, I forgot to remove @index. Even so it continues with the same errorMario

2 Answers

4
votes

You have an extra "}" on your controller, right below index method.

And you'll need to close the class, adding a } after destroy method.

2
votes

In Route::resource() has 7 methods bind.

If you want to use Route::resource() then you should pass two params, base path and Controller class. see

SO you should pass like this.

Route::resource('usuarios', 'UserController');

Notice that:

Route::resource('usuarios', 'UserController'); second parameter is a controller class name.

where you are using Route::resource('usuarios', 'UserController@index'); is not a class, passing index method exits in UserController class.