Advertisement
dadang9

Eager Loading

May 21st, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. Tables creation:
  2.  
  3. product
  4.  
  5. id | primary key, unsigned, integer
  6. kd_barang | unique, nullable, FK constraint
  7. nama_roti
  8. harga
  9. timestamps()
  10.  
  11. transaksi
  12.  
  13. id_transaksi | primary key, varchar
  14. kd_barang | FK Constraint to product table
  15. jumlah
  16. harga satuan
  17. total_harga
  18. timestamps
  19.  
  20. Relationships:
  21.  
  22. App\Product
  23.  
  24.  public function transaction()
  25.     {
  26.         return $this->hasMany(Transaction::class, 'kd_barang');
  27.     }
  28.  
  29. App\Transaction
  30.  
  31.         protected $table = 'transaksi';
  32.     protected $primaryKey = 'id_transaksi';
  33.     protected $fillable = ['kd_barang', 'jumlah' , 'harga_satuan', 'total_harga'];
  34.     public $incrementing = false;
  35.  
  36. public function product()
  37.     {
  38.         return $this->belongsTo(Product::class, 'kd_barang');
  39.     }
  40.  
  41. <a href="https://imgur.com/UZY6hJK"><img src="https://i.imgur.com/UZY6hJK.png" title="source: imgur.com" /></a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement