I am using laravel query which is taking long time and then failed. I tried many ways but nothing worked.
This is the query
$consignments = Consignment::where('customer_id', $invoice->customer_id)->doesnthave('invoice_charges')->get();
here is consignment model which is having Many relationships
<?php
namespace App\Models\Admin;
use Illuminate\Database\Eloquent\Model;
class Consignment extends Model
{
protected $table = 'consignments';
/**
* @var array
*/
protected $guarded = [];
/**
* @var array
*/
protected $hidden = [
'created_at', 'updated_at'
];
public function pickupConsignment()
{
return $this->hasOne('App\Models\Admin\PickupDeliveryConsignment', 'pickup_consignment_id');
}
public function deliveryConsignment()
{
return $this->hasOne('App\Models\Admin\PickupDeliveryConsignment', 'delivery_consignment_id');
}
public function customers()
{
return $this->belongsTo('App\Models\Admin\Customer', 'customer_id');
}
public function income_charge_schemes()
{
return $this->hasOne('App\Models\Admin\IncomeChargeScheme', 'consignment_id');
}
}
As you see consignment model has many relationships but i think query fetch all the relationships data with it .
When I use toBase()
It gets load quickly but it doesn't fetch relationship which is required
here is the query with toBase()
$consignments = Consignment::where('customer_id', $invoice->customer_id)->doesnthave('invoice_charges')->toBase()->get();
I think this relationship which is creating issue
I also tried cursor()
function but didn't work ..
How i can optimize this query any suggestion?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/32YEDqb
via IFTTT
Aucun commentaire:
Enregistrer un commentaire