【问题标题】:Eloquent Create Only Inserting Blank FieldsEloquent 创建只插入空白字段
【发布时间】:2015-06-21 21:18:44
【问题描述】:

我已将我的代码精简到最低限度,但我想输入的字段仍然被 Eloquent 设置为空白。我已将所有必要的字段设置为可填写,并且可以更新最初设置为空白的字段。

我在 Eloquent 中使用 Slim 框架。

帖子:

$app->post('/register', function() use($app){
    $request = $app->request;

$username = $request->post('username');
//this if was for validation which I removed for testing
if(true){
    $app->user->where('username', 'B1401812')->update(['username'=> 'FRANK']);
    $app->user->create(array(
        'username' => 'bob',
        'password' => 'ptest'
    ));
}else{
    $app->render('auth/register.php', [
        'errors'=> $v->errors(),
        'request' => $request
    ]);

}

用户模型:

class User extends Eloquent
{
protected $table = 'user_information';


protected $fillable = [
    'username',
    'password',
    'active',
    'banner_location',
    'profile_picture_location'
];
public function __construct()
{

}
...some other functions

我尝试了建议的解决方案,例如禁用批量分配保护,但没有成功。

【问题讨论】:

  • 你能编辑你的问题,添加你的整个路线功能吗?
  • 没问题,我已经添加了其余部分。

标签: eloquent slim


【解决方案1】:

我不知道 Slim 是如何利用 Eloquent 的,但你能试试下面的代码吗?

User::create(array(
        'username' => 'bob',
        'password' => 'ptest'
    ));

我不确定$app->user 的实例指的是什么。

【讨论】:

  • 对不起,只是为了澄清 $app->user 只是一个返回新用户的函数,我认为这不是问题,因为它确实插入了行,只是用户名和密码字段在该行上设置为空白
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-10
  • 1970-01-01
相关资源
最近更新 更多