很难解释我需要什么,但是我会尽力的。
$this->order->where("client_id", 5)
->with([
"roadOrderStatus" => function ($query) {
$query->select("id", "identifier");
},
"currency" => function ($query) {
$query->join("translations", "currencies", '=', 'translations.id')
->join('translation_entries', 'translations.id', '=', 'translation_entries.translation_id')
->join('languages', 'translation_entries.language_id', '=', 'languages.id')
->whereIn('languages.code', ["eng"]);
},
])->get();
我在订单上有两个关系(roadOrderStatus和currency)。如果在回调中,我什么也没写,响应很好。有用。但是货币需要转换,因为(货币表中有一个名为name的列,并且它是整数,因为它得到了转换)。因此,如果您查看我的代码,则在获取货币关系时,我还需要加入到翻译中以获取翻译后的货币,但是,如果我在上述的货币关系回调中编写了加入,它将返回-currency - null
我尝试-
1) ->whereIn('languages.code', ["eng"])->get();
2) return $query->join("translations", .e.t.c)
我的订单模型-
<?php
namespace App\Http\Models\Orders;
use App\Http\Traits\ScopeTrait;
use Illuminate\Database\Eloquent\Model;
class RoadOrder extends Model
{
use ScopeTrait;
public function orderFinancialProperty(){
return $this->morphOne("App\Http\Models\Orders\OrderFinancialProperty", "orderFinancialPropertable");
}
public function roadOrderStatus(){
return $this->belongsTo("App\Http\Models\Orders\RoadOrderStatus");
}
public function roadTransportType(){
return $this->belongsTo("App\Http\Models\Transport_Type\RoadTransportType");
}
public function currency(){
return $this->belongsTo('App\Http\Models\Statics\Currency');
}
public function insurancer(){
return $this->belongsTo("App\Http\Models\Insurance\Insurancer");
}
}