[wip] create main tables relation
This commit is contained in:
76
app/Models/FormCuti.php
Normal file
76
app/Models/FormCuti.php
Normal 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];
|
||||
// }
|
||||
// }
|
||||
}
|
||||
22
app/Models/Group.php
Normal file
22
app/Models/Group.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\AclGroupFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Group extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Create a new factory instance for the model.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
||||
*/
|
||||
protected static function newFactory()
|
||||
{
|
||||
return AclGroupFactory::new();
|
||||
}
|
||||
}
|
||||
46
app/Models/Pengajuan.php
Normal file
46
app/Models/Pengajuan.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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;
|
||||
|
||||
class Pengajuan extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'form_cuti';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'tgl_mulai', 'tgl_selesai',
|
||||
];
|
||||
|
||||
public function personalia(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'terima_personalia');
|
||||
}
|
||||
|
||||
public function supervisor(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'terima_supervisor');
|
||||
}
|
||||
|
||||
public function disetujuiOleh(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn ($value) => collect($this->personalia, $this->supervisor)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,15 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Junges\ACL\Concerns\HasGroups;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
use HasApiTokens, HasFactory, HasGroups, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
@@ -41,4 +43,13 @@ class User extends Authenticatable
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function formCuti(): HasOne
|
||||
{
|
||||
if ($this->hasGroup('personalia')) {
|
||||
return $this->hasOne(FormCuti::class, 'creator');
|
||||
} else {
|
||||
return $this->hasOne(FormCuti::class, 'staff');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user