Reputation: 32951
I am making registration system in laravel. When user inputs data then I store it in database. But when user clicked register button, then it gives me following error 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
When I change the name of the table to "user" then says Unhandled Exception
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
How can I solve this problem?
UPDATE CODE
Here are my models
user.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'
);
}
Basemodel.php
class Basemodel extends Eloquent {
public static function validate($data) {
return Validator::make($data, static::$rules);
}
}
Here is my users.php controller
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();
}
}
}
Upvotes: 1
Views: 3495
Reputation: 2893
Having just suffered through this issue, I can tell you exactly what it is. Double check your "unique:" validation constraint.
Your unique constraint above says "user", so laravel's Validator is looking for that table to do it's validations.
Change that to "users" and voila! Problem solved.
Upvotes: 2
Reputation: 12965
The error message says there is no table "makeitsnappy" so it seems that this comes from outside the code that you posted here IMO.
Upvotes: 0