2
votes

I created a controller in Laravel, but when I call a method on the Controller it shows the following error:

BadMethodCallException Method [Register] does not exist on [App\Http\Controllers\UserController].

Controller Code:

namespace App\Http\Controllers;

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

class UserController extends Controller
{

public function Index()
{
        echo "hello";
}

public function Register()
{
    $user = new User();
    $user->name = "Aisha";
    $user->email = "[email protected]";
    $user->password = "TestPass";
    $user->remember_token = str_random(16);
    $user->save();
}
}

Route:

Route::get('/user/register','UserController@Register');
1
Please show the route and controller.Alexey Mezenin
I added the codeaishazafar
Thanks its workingaishazafar
Glad it helped.Alexey Mezenin

1 Answers

-2
votes
public function Register()
{
    $user = new User; // Create a new User collection..
    $user->name = "Aisha";
    $user->email = "[email protected]";
    $user->password = "TestPass";
    $user->remember_token = str_random(16);
    $user->save();
}