我有一個關於laravel關係的問題OneToMany。我的數據庫有2個表產品和product_entry。產品將有信息選擇相同的價格...和product_entry將有關於信息的信息。Laravel - 選擇孩子在哪裏參數
1產品有很多product_entry會另一種語言。但網站只有1種語言在同一時間,所以無論如何,我只選擇product_entry有product_entry_language相同的當前語言?
例如:我有1個產品與語言「EN」和「ES」。正常,當前的語言是「en」。在刀片,我必須的foreach產品 - > product_entries如果(product_entry_language == 「EN」){**獲取信息**} =>我想並不需要運行的foreach
型號
class Product extends Model
{
use TransformableTrait;
protected $table = 'product';
protected $fillable = ['product_code','product_id'];
public function entries()
{
return $this->hasMany('App\Entities\ProductEntry', 'product_entry_product_id', 'product_id');
}
}
class ProductEntry extends Model
{
use TransformableTrait;
protected $table = 'product_entry';
protected $fillable = ['product_entry_product_id','product_entry_name'];
}
也請發表您的機型。 –
我已添加模型 –