SptpdRincianReklame.php
1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* @Author: irul
* @Date: 2019-09-23 15:29:45
* @Last Modified by: irul
* @Last Modified time: 2019-10-01 23:43:21
*/
namespace Integrasi\Reklame\Base\Models;
use \Illuminate\Database\Capsule\Manager as DB;
class SptpdRincianReklame extends AbstractModel
{
protected $table = 'pad_sptpd_rk_det';
protected $guarded = array();
public $timestamps = false;
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
return $model->_onCreating();
});
}
public function _onCreating()
{
$maxReklameKe = call_user_func($this->getParentNamespace() . '\SptpdRincianReklame::select',
DB::raw('max(reklame_ke) as nomor'))
->where(DB::raw('sptpd_id'), $this->attributes['sptpd_id'])
->first();
$reklameKe = ($maxReklameKe->nomor ?: 0) + 1;
$this->attributes['reklame_ke'] = $reklameKe;
return true;
}
// == RELATIONSHIPS == //
/**
* Get the sptpd that owns the sptpd_rincian_reklame.
*/
public function sptpd()
{
return $this->belongsTo($this->getParentNamespace() . '\Sptpd', 'id', 'sptpd_id');
}
}