我正在 laravel 中制作注册系统。当用户输入数据时,我将其存储在数据库中。但是当用户单击注册按钮时,它会给我以下错误 Unhandled Exception
Message:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'makeitsnappy.user' doesn't exist
SQL: SELECT COUNT(*) AS `aggregate` FROM `user` WHERE `username` = ?
Bindings: array (
0 => 'asdasd',
)
Location:
/Applications/MAMP/htdocs/laravel-test/laravel/database/connection.php on line 264
当我将表的名称更改为“用户”时,会说未处理的异常
Message:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'makeitsnappy.users' doesn't exist
SQL: INSERT INTO `users` (`username`, `password`, `updated_at`, `created_at`) VALUES (?, ?, ?, ?)
Bindings: array (
0 => 'zafar',
1 => '$2a$08$Xg47q9n65GZSS/l3xgYTyeTC7eICqMimf6KkvdFwSfiOgpFrI0tKe',
2 => '2013-03-31 09:22:48',
3 => '2013-03-31 09:22:48',
)
Location:
/Applications/MAMP/htdocs/laravel-test/laravel/database/connection.php on line 264
我怎么解决这个问题?
更新代码
这是我的模型
用户.php
class User extends Basemodel {
public static $table = 'users';
public static $rules = array(
'username'=>'required|unique:user|alpha_dash|min:4',
'password'=>'required|alpha_num|between:4,8|confirmed',
'password_confirmation'=>'required|alpha_num|between:4,8'
);
}
基本模型.php
class Basemodel extends Eloquent {
public static function validate($data) {
return Validator::make($data, static::$rules);
}
}
这是我的 users.php 控制器
class Users_Controller extends Base_Controller {
public $restful = true;
public function get_new() {
return View::make('users.new')->with('title', 'Make it Snappy - Register');
}
public function post_create() {
$validation = User::validate(Input::all());
if($validation->passes()) {
User::create(array(
'username' => Input::get('username'),
'password' => Hash::make(Input::get('password'))
));
return Redirect::to_route('home')->with('message', 'Thanks for registring');
} else {
return Redirect::to_route('register')->with_errors($validation)->with_input();
}
}
}