eloquent variant in laravel
{"id":"3314","provinsi_id":"33","nama":"Kab. Sragen"}
protected $hidden = ['id'];
{"provinsi_id":"33","nama":"Kab. Sragen"}
protected $visible = ['nama'];
{"nama":"Kab. Sragen"}
protected $appends = ['nama_provinsi'];
// accessor
public function getNamaProvinsiAttribute()
{
return $this->provinsi->nama;
}
//agar sebuah database tidak perlu mengunakan create_at&update_at
public $timestamps = false;
protected $fillable = ['nama', 'provinsi_id'];
$user->created_at->diffForHumans() // output: 1 years ago
$user->created_at->diffInDays() // output: 365
protected $dates = ['tanggal_berdiri'];
286 years ago
{"nama":"Kab. Sragen","has_adipura":"0","nama_provinsi":"Jawa Tengah"}
protected $casts = [
'has_adipura' => 'boolean'
];
{"nama":"Kab. Sragen","has_adipura":false,"nama_provinsi":"Jawa Tengah"}