1

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();
        }
    }
}
9
  • 1
    What does the db-schema look like? Commented Mar 31, 2013 at 10:20
  • If you're using Eloquent & a non-standard name (or at least a name Laravel can't deal with) set public static $table = 'tablename'; of your model. Commented Mar 31, 2013 at 10:32
  • @Wrikken where do I set $tablename? Commented Mar 31, 2013 at 10:34
  • You probably have a user class... set it there. Commented Mar 31, 2013 at 10:35
  • After adding public static $table = 'tablename'; still have the same problem. Commented Mar 31, 2013 at 10:37

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

The error message says there is no table "makeitsnappy" so it seems that this comes from outside the code that you posted here IMO.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.