gpt4 book ai didi

php - laravel 中的数据库表有问题

转载 作者:搜寻专家 更新时间:2023-10-30 23:14:47 26 4
gpt4 key购买 nike

我正在 laravel 中制作注册系统。当用户输入数据时,我将其存储在数据库中。但是当用户点击注册按钮时,它给了我跟随错误 未处理的异常

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 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();
}
}
}

最佳答案

刚刚经历过这个问题,我可以准确地告诉你它是什么。仔细检查您的“唯一:”验证约束。

你上面的唯一约束说“用户”,所以 laravel 的验证器正在寻找那个表来做它的验证。

将其更改为“用户”,瞧!问题解决了。

关于php - laravel 中的数据库表有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15728417/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com