【发布时间】:2018-10-08 08:58:40
【问题描述】:
我写了一个代码来登录或注册用户。如果用户不存在,我使用 updateOrCreate 函数添加用户,如果用户存在,则更新名称为验证码的列
控制器
users Table:
id(auto increment primary key)|phone|verifcode|timeStmp
---------------------------------
$phone=Input::get('phone');
$code=rand(1001,9999);
$user = new user;
$user = array('phone'=>$phone);
user::updateOrCreate($user,['verifcode' => $code]);
型号:
namespace App;
use Illuminate\Database\Eloquent\Model;
class user extends Model
{
protected $table = 'users';
protected $fillable = array('phone', 'verifcode','timeStmp');
protected $guarded = array('id');
protected $primaryKey = "id";
public $incrementing = false;
const CREATED_AT= false;
const UPDATED_AT = false;
}
使用此代码我有以下错误:
array_key_exists(): The first argument should be either a string or an integer 指向vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasAttributes.php 文件。
我只知道错误指向 UpdateOrCreate 函数的第二个参数。
感谢帮助
【问题讨论】:
-
我已经回答了。请检查并告诉我它是否适合您。谢谢