0
두 개의 테이블 invoice_header
및 invoice_detail
두 테이블의 참조 키는 loc_id
및 invo_no
입니다.Laravel | oneToMany 두 개의 외래 키
모델 내부에서 어떻게 연결할 수 있습니까? 외래 키 배열을 사용할 수 있습니까?
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class InvoiceDetail extends Model
{
protected $table = 'invoice_detail';
public $timestamps = false;
protected $fillable = ['invo_no','loc_id','serial','item_id','qty','rtp','cost',
'discount','type'];
public function item(){
return $this->belongsTo('App\InvoiceHeader', ['loc_id', 'invo_no']);
}
}
세부 사항 $ 세부 정보 -> 헤더를 통해 헤더를받을 수 있습니까? – CairoCoder
네, 내가 인보이스 모델에 대해 쓴 것과 똑같은 일을 할 것이고, 사용중인 fks를 지정하는 방법을 알려주는 문서가 있습니다. –
'return $ this-> hasMany ('App \ Comment', 'foreign_key', 'local_key') ; ' –