0
我正在創建一個表格,顯示請求列表,我在ID的'erp_createdid'和'erp_productid'之間有關係。爲了顯示產品的名稱,我創建了一個belongsToMany,其中我指定了我的兩個'ID's'。BelongToMany的Laravel 5.4不起作用
訂貨型號
class Order extends Model
{
protected $table = 'erp_order';
protected $fillable = ['erp_createdid'];
protected $primaryKey = 'erp_orderid';
public function description()
{
return $this->belongsToMany('App\Description','erp_order_product', 'erp_createdid', 'erp_productid');
}
}
描述型號
class Description extends Model
{
protected $table = 'erp_product_description';
protected $primaryKey = 'erp_productid';
protected $fillable = ['erp_name'];
public $timestamps = false;
public function order()
{
return $this->belongsToMany('App\Order', 'erp_order_product', 'erp_createdid', 'erp_productid');
}
表
<td>@foreach($orders->description as $des)
{{$des->erp_name}}
@endforeach
</td>
但在價值觀表不顯示,有什麼建議?
沒有工作,同樣的事情。 –
然後你可以顯示更多的代碼嗎? '$ orders'是什麼? – Jan
$ order = Order :: orderBy('erp_orderid','desc') - > paginate(20); –