我正在使用带有laravel-datatables插件的laravel 5.4
我对调试器插件和正常的幼虫日志错误没有问题,但由于某种原因,其中一个Bug根本没有显示,而laraval显示白页没有错误:(
我相信与我的Eloquent关系相关的代码会出现以下代码产品白页错误
return Datatables::of(InvoiceProduct::where('purchasing_order_id', 1))->make(true);
只有在数据库purchase_orders为非空时才会出现上述错误。
我也使用DB来尝试获得与以下相同的结果和错误
return Datatables::of(DB::select('select * from invoice_products where purchasing_order_id = ' . $id))->make(true);
我真的需要看看什么是错误,所以我可以解决它:(
答案 0 :(得分:1)
我发现我的代码存在问题,但仍然不知道为什么500错误没有登录存储/日志,仍然不知道为什么白页,仍然不知道如何解决它。
问题是当我删除protect $ with arrays中的invoice_product时,错误就消失了。
以下是我编辑的代码。
//protected $with = ['invoice_products', 'customer', 'currency', 'company'];
//Comment out above line, the below line is working
protected $with = ['customer', 'currency', 'company'];
我认为我的关系错了,但找不到问题,
这是我的“purchase_orders模型”Eloquent模型的代码,它有很多“invoice_products”
class PurchasingOrder extends Model
{
protected $table = 'purchasing_orders';
protected $fillable = [
'po_number', 'po_date',
'invoice_reference', 'customer_id', 'customer_po_number', 'agent',
'estimate_shipping_date', 'estimate_arrival_date', 'estimate_loading_date',
'ship_to','to_user_name',
'term', 'po_remark', 'worksheet_remark',
'company_id','currency_id',
'total_amount', 'total_quantity','total_net_weight','total_gross_weight','total_packed_cu_metric','total_pallets',
];
//Json come with product_unit and supplier that associated with prdocut
//protected $with = ['invoice_products', 'customer', 'currency', 'company'];
protected $with = ['customer', 'currency', 'company'];
/**
* Get the invoice_product of invoice.
*/
//One invoice has many invoice_product
public function invoice_products()
{
return $this->hasMany('App\InvoiceProduct');
}
/**
* Get the customer of invoice.
*/
//One invoice has only one customer
public function customer()
{
return $this->belongsTo('App\Customer', 'customer_id');
}
/**
* Get the currency of invoice.
*/
//One invoice has only one currency
public function currency()
{
return $this->belongsTo('App\Currency', 'currency_id');
}
/**
* Get the company of invoice.
*/
//One invoice has only one company
public function company()
{
return $this->belongsTo('App\Company', 'company_id');
}
这是我的代码来自“invoice_products”Eloquent模型(属于purchase_order Eloquent模型)
class InvoiceProduct extends Model
{
protected $table = 'invoice_products';
protected $fillable = [
'product_id', 'customer_product_id','name', 'brand', 'packing',
'gross_weight', 'net_weight','net_weight_packing',
'product_unit_id', 'packed_cu_metric',
'quantity','price','amount','pallets',
'invoice_id', 'purchasing_order_id','container_id',
];
//Json come with InvocieProduct add PurchasingOrder
protected $with = ['purchasing_order', 'product', 'customer_product', 'container'];
public function purchasing_order()
{
return $this->belongsTo('App\PurchasingOrder', 'purchasing_order_id');
}
public function container()
{
return $this->belongsTo('App\Container');
}
public function product()
{
return $this->belongsTo('App\Product', 'product_id');
}
public function customer_product()
{
return $this->belongsTo('App\CustomerProduct', 'customer_product_id');
}
}
答案 1 :(得分:0)
您正在使用查询构建器,这不是标准获取结果,您需要使用->get()
链接您的呼叫
return Datatables::of(InvoiceProduct::where('purchasing_order_id', 1)->get())->make(true);
这不仅会创建查询,还会执行它。
答案 2 :(得分:0)
您应该做的是查看错误日志文件。打开storage/logs
目录,您会发现500错误的原因。例如,它可能是无效的列名,不是导入的模型,也可能是其他原因。