【发布时间】:2019-02-23 15:39:54
【问题描述】:
下面是我的注册控制器中的一段代码。如您所见,每个字段都有一个值,但它没有插入到数据库中。如果值不存在,我已经为数据库中的这些字段配置了默认值。它使行没有默认值。我无法弄清楚问题所在。我还可以在模型中填写所有字段。
protected function create(array $data)
{
$user = Account::create([
'wallet' => $data['wallet'],
'email' => $data['email'],
'balance' => 0,
'uqid' => rand(10000000,99999999) ,
'ref' => 0,
]);
$gnl = General::first();
$track = Track::create([
'account_id' => $user->id,
'speed' => $gnl->dhs_free,
'balance' => 0,
'uqid' => rand(10000000,99999999) ,
'ref' => 0,
]);
帐户模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Account extends Model
{
protected $fillable = ['wallet','uqid','ref','bstatus','refcom','email','verified'];
public function deposit()
{
return $this->hasMany('App\Deposit','id','account_id');
}
public function withdraw()
{
return $this->hasMany('App\Withdraw','id','account_id');
}
public function track()
{
return $this->hasMany('App\Track','id','account_id');
}
跟踪模型
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Track extends Model
{
protected $fillable = array( 'account_id','speed','withdraw','status');
public function account()
{
return $this->belongsTo('App\Account');
}
}
【问题讨论】:
-
如果有解释,您可以查看日志文件吗? (storage/logs/laravel.log)
-
我检查了很多次都没有错误
-
你能告诉我们你得到的确切错误信息吗?
-
1. colmn 后面的错误没有默认值。 2.如果我将默认值添加到 colmn 然后它只插入默认值而不是来自控制器
-
请在您的问题中也发布您的模型