[wip] create main tables relation

This commit is contained in:
gregorio
2022-07-26 07:01:25 +07:00
parent f98ca8d532
commit 5021507cf6
32 changed files with 1324 additions and 168 deletions

76
app/Models/FormCuti.php Normal file
View File

@@ -0,0 +1,76 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Arr;
class FormCuti extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var string[]
*/
protected $fillable = [
'keterangan',
'data',
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'data' => 'array',
];
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'form_cuti';
public function staff(): BelongsTo
{
return $this->belongsTo(User::class, 'staff_id');
}
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'creator_id');
}
// public function createRow(array $row): void
// {
// $row = Arr::only($row, ['tgl_mulai', 'tgl_selesai']);
// $row['form_cuti_id'] = $this->id;
// $row['supervisor'] = [
// 'id' => null,
// 'terima' => false,
// 'keterangan' => null,
// ];
// $row['personalia'] = [
// 'id' => $this->creator->id,
// 'terima' => false,
// 'keterangan' => null,
// ];
// // this runs setDataAttribute
// if (isset($this->attributes['data'])) {
// $this->data = array_merge($this->attributes['data'], [$row]);
// } else {
// $this->data = [$row];
// }
// }
}