【发布时间】:2020-08-13 23:23:01
【问题描述】:
我只是通过实例化一个模型并设置一个属性来得到这个错误。
$order_datail = new OrderDetail;
$order_detail->quantity = $product['quantity'];
我正在寻找这个问题的原因,但找不到。
OrderDetail 的构造函数被执行。表是 order_details,但即使设置受保护的 $table = 'order_details',我仍然会收到此错误。是的,此表中有一个“数量”列。
奇怪的是,我对其他模型没有任何问题。
$order = new Order;
$order->pickup_date = $request['date'];
$order->pickup_time = $request['pickupTime'];
以上代码运行良好。
型号订单详情:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class OrderDetail extends Model
{
use SoftDeletes;
public function replaceds()
{
return $this->hasMany('App\Models\Replaced');
}
public function orders()
{
return $this->belongsTo('App\Models\Order');
}
public function products()
{
return $this->hasMany('App\Models\Product');
}
public function collis()
{
return $this->hasMany('App\Models\Colli');
}
}
有谁知道这可能是什么原因?
【问题讨论】:
-
你能展示你的模型吗?
-
抱歉,更新了问题
-
请更正您在 $order_datail = new OrderDetail 中的拼写;它应该是“order_detail”
-
你不能是认真的......检查了很多次。捂脸!