我正在将laravel 5.4与laravel-datatables插件一起使用
我没有调试器插件和正常的幼虫日志错误的问题,但是由于某种原因,其中一个Bug根本没有显示,而laravel显示白页却没有错误:(
我相信与我的 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);
我真的需要查看错误是什么,以便我可以解决它:(
最佳答案
我发现了我的代码存在的问题,但是仍然不知道为什么500错误没有在存储/日志中登录,仍然不知道为什么是白页,并且仍然不知道如何解决。
问题是当我在保护$ with数组中删除invoice_product时,错误消失了。
这是我编辑的代码。
//protected $with = ['invoice_products', 'customer', 'currency', 'company'];
//Comment out above line, the below line is working
protected $with = ['customer', 'currency', 'company'];
我相信我的关系是错误的,但找不到问题,
这是我的“购买订单模型” Eloquent 模型代码,其中包含许多“发票产品”
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');
}
}
关于php - laravel,已记录正常错误,但白屏只有一个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45780549/