Skip to content

Instantly share code, notes, and snippets.

@gravitano
Last active August 29, 2015 14:21
Show Gist options
  • Save gravitano/fc8b2f2a43b8b080de99 to your computer and use it in GitHub Desktop.
Save gravitano/fc8b2f2a43b8b080de99 to your computer and use it in GitHub Desktop.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Barang extends Model {
protected $primaryKey = 'id_barang';
public function kondisi()
{
return $this->belongsTo('App\Kondisi', 'id_kondisi', 'kondisi_id');
}
}
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Kondisi extends Model {
protected $primaryKey = 'kondisi_id';
}
$pinjam = Pinjam::first();

$barang = $pinjam->barang;

$kondisi = $barang->kondisi->field_yang_akan_diambil;

// atau

$kondisi = $pinjam->barang->kondisi->field_yang_akan_diambil;
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Pinjam extends Model {
protected $primaryKey = 'id';
public function barang()
{
return $this->belongsTo('App\Barang', 'lbl_brg', 'id_barang');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment