首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >laravel,记录正常错误,但只有一个错误显示白屏

laravel,记录正常错误,但只有一个错误显示白屏
EN

Stack Overflow用户
提问于 2017-08-20 17:25:53
回答 3查看 81关注 0票数 1

我正在使用带有laravel-datatables插件的laravel 5.4

我没有问题的调试器插件和正常的幼虫日志错误,但由于某些原因,其中一个Bug根本不显示和幼虫显示白色页面没有错误:(

我相信代码与我的雄辩关系问题有关,下面的代码产品白页错误

代码语言:javascript
复制
return Datatables::of(InvoiceProduct::where('purchasing_order_id', 1))->make(true);

仅当数据库purchasing_orders不为空时,才会出现上述错误。

我还使用DB来尝试获得与以下相同的结果,但没有使用and和Error

代码语言:javascript
复制
return Datatables::of(DB::select('select * from invoice_products where purchasing_order_id = ' . $id))->make(true);

我真的需要看看错误是什么,这样我才能修复它:(

EN

回答 3

Stack Overflow用户

发布于 2017-08-20 20:42:14

我发现了我的代码的问题,但仍然不知道为什么500错误没有记录在存储/日志中,仍然不知道为什么是白页,仍然不知道如何修复它。

问题是当我在protect $with阵列中删除invoice_product时,错误消失了。

这是我编辑的代码。

代码语言:javascript
复制
//protected $with = ['invoice_products', 'customer', 'currency', 'company'];
//Comment out above line, the below line is working
protected $with = ['customer', 'currency', 'company'];

我相信我的关系是错误的,但找不到问题所在,

下面是我的"purchasing_orders模型“雄辩模型的代码,其中有许多"invoice_products”

代码语言:javascript
复制
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模型(属于purchasing_order Eloquent模型)的代码。

代码语言:javascript
复制
    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
EN

Stack Overflow用户

发布于 2017-08-20 18:19:45

您正在使用查询构建器,这不是获取结果的标准,您需要使用->get()链接您的调用

代码语言:javascript
复制
return Datatables::of(InvoiceProduct::where('purchasing_order_id', 1)->get())->make(true);

这不仅会创建查询,还会执行查询。

票数 0
EN

Stack Overflow用户

发布于 2017-08-20 19:59:51

您应该做的是查看错误日志文件。打开storage/logs目录,你会发现500错误的原因。例如,可能是无效的列名,不是导入的模型,或者可能是其他原因。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45780549

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档