我在Laravel中创建了一个控制器,但是当我在Controller上调用一个方法时,它显示以下错误:
BadMethodCallException 方法[注册]在[App \ Http \ Controllers \ UserController]上不存在。
控制器代码:
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 = "aishaemail@yahoo.com";
$user->password = "TestPass";
$user->remember_token = str_random(16);
$user->save();
}
}
路线:
Route::get('/user/register','UserController@Register');
答案 0 :(得分:-2)
public function Register()
{
$user = new User; // Create a new User collection..
$user->name = "Aisha";
$user->email = "aishaemail@yahoo.com";
$user->password = "TestPass";
$user->remember_token = str_random(16);
$user->save();
}