big update base struktur tahap 1
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MenuGroup extends Model
|
||||
{
|
||||
protected $table = 'menu_groups';
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id',
|
||||
'name',
|
||||
'description',
|
||||
'is_system',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'is_system' => 'boolean',
|
||||
];
|
||||
|
||||
public function menus()
|
||||
{
|
||||
return $this->belongsToMany(
|
||||
MenuList::class,
|
||||
'menu_group_menus',
|
||||
'menu_group_id',
|
||||
'menu_id'
|
||||
)->withPivot([
|
||||
'can_view',
|
||||
'can_create',
|
||||
'can_update',
|
||||
'can_delete',
|
||||
'can_approve',
|
||||
'can_export',
|
||||
])->withTimestamps();
|
||||
}
|
||||
|
||||
public function userMenuGroups()
|
||||
{
|
||||
return $this->hasMany(UserMenuGroup::class, 'menu_group_id');
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MenuGroupMenu extends Model
|
||||
{
|
||||
protected $table = 'menu_group_menus';
|
||||
|
||||
protected $fillable = [
|
||||
'menu_group_id',
|
||||
'menu_id',
|
||||
'can_view',
|
||||
'can_create',
|
||||
'can_update',
|
||||
'can_delete',
|
||||
'can_approve',
|
||||
'can_export',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'can_view' => 'boolean',
|
||||
'can_create' => 'boolean',
|
||||
'can_update' => 'boolean',
|
||||
'can_delete' => 'boolean',
|
||||
'can_approve' => 'boolean',
|
||||
'can_export' => 'boolean',
|
||||
];
|
||||
|
||||
public function menuGroup()
|
||||
{
|
||||
return $this->belongsTo(MenuGroup::class, 'menu_group_id');
|
||||
}
|
||||
|
||||
public function menu()
|
||||
{
|
||||
return $this->belongsTo(MenuList::class, 'menu_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\Auditable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MenuList extends Model
|
||||
{
|
||||
use Auditable;
|
||||
|
||||
protected $table = 'menu_lists';
|
||||
|
||||
protected $fillable = [
|
||||
'parent_id',
|
||||
'name',
|
||||
'slug',
|
||||
'url',
|
||||
'icon',
|
||||
'component',
|
||||
'sort_order',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
];
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Relationships
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(self::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(self::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function menuGroups()
|
||||
{
|
||||
return $this->belongsToMany(
|
||||
MenuGroup::class,
|
||||
'menu_group_menus',
|
||||
'menu_id',
|
||||
'menu_group_id'
|
||||
)->withPivot([
|
||||
'can_view',
|
||||
'can_create',
|
||||
'can_update',
|
||||
'can_delete',
|
||||
'can_approve',
|
||||
'can_export',
|
||||
])->withTimestamps();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class NasMikrotik extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $hidden = ['api_password', 'radius_secret'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['api_password' => 'encrypted', 'radius_secret' => 'encrypted'];
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class NasOlt extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $hidden = ['community', 'auth_password', 'privacy_password'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'community' => 'encrypted',
|
||||
'auth_password' => 'encrypted',
|
||||
'privacy_password' => 'encrypted',
|
||||
];
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class NasPackageProfile extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['price' => 'decimal:2'];
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class NasWebfigDevice extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $hidden = ['password'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['password' => 'encrypted'];
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class StoredFile extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'uuid',
|
||||
'tenant_id',
|
||||
'uploaded_by',
|
||||
'disk',
|
||||
'bucket',
|
||||
'object_key',
|
||||
'original_name',
|
||||
'extension',
|
||||
'mime_type',
|
||||
'size',
|
||||
'category',
|
||||
'visibility',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['size' => 'integer'];
|
||||
}
|
||||
|
||||
public function getRouteKeyName(): string
|
||||
{
|
||||
return 'uuid';
|
||||
}
|
||||
|
||||
public function uploader(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'uploaded_by');
|
||||
}
|
||||
|
||||
public function tenant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Tenant extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'tenant_code',
|
||||
'tenant_name',
|
||||
'phone',
|
||||
'email',
|
||||
'address',
|
||||
'status',
|
||||
];
|
||||
}
|
||||
+63
-15
@@ -2,19 +2,25 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\UserAccessLevel;
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
// use App\Traits\Auditable;
|
||||
|
||||
// use App\Traits\Auditable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
use HasApiTokens;
|
||||
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
use SoftDeletes;
|
||||
// use Audittable;
|
||||
|
||||
/**
|
||||
@@ -24,8 +30,19 @@ class User extends Authenticatable
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'username',
|
||||
'email',
|
||||
'whatsapp_number',
|
||||
'profile_photo_file_id',
|
||||
'password',
|
||||
'is_master',
|
||||
'access_level',
|
||||
'status',
|
||||
'verification_channel',
|
||||
'verification_target',
|
||||
'verification_code',
|
||||
'verification_code_expires_at',
|
||||
'verified_at',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -48,24 +65,55 @@ class User extends Authenticatable
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'is_master' => 'boolean',
|
||||
'access_level' => UserAccessLevel::class,
|
||||
'verification_code_expires_at' => 'datetime',
|
||||
'verified_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function login(Request $request)
|
||||
public function menuGroups()
|
||||
{
|
||||
$user = User::where('email', $request->email)->first();
|
||||
return $this->belongsToMany(
|
||||
MenuGroup::class,
|
||||
'user_menu_groups',
|
||||
'user_id',
|
||||
'menu_group_id'
|
||||
)->withPivot(['tenant_id'])->withTimestamps();
|
||||
}
|
||||
|
||||
if (!$user || !Hash::check($request->password, $user->password)) {
|
||||
return response()->json([
|
||||
'message' => 'Login gagal'
|
||||
], 401);
|
||||
}
|
||||
public function userProfile()
|
||||
{
|
||||
return $this->hasOne(UserProfile::class, 'user_id');
|
||||
}
|
||||
|
||||
$token = $user->createToken('services-core')->plainTextToken;
|
||||
public function profilePhoto()
|
||||
{
|
||||
return $this->belongsTo(StoredFile::class, 'profile_photo_file_id');
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'token' => $token,
|
||||
'user' => $user
|
||||
]);
|
||||
public function userTenants()
|
||||
{
|
||||
return $this->hasMany(UserTenant::class, 'user_id');
|
||||
}
|
||||
|
||||
public function userMenuGroups()
|
||||
{
|
||||
return $this->hasMany(UserMenuGroup::class, 'user_id');
|
||||
}
|
||||
|
||||
public function isMasterAdmin(): bool
|
||||
{
|
||||
return $this->is_master || $this->access_level === UserAccessLevel::MASTER_ADMIN;
|
||||
}
|
||||
|
||||
public function isTenantOwner(): bool
|
||||
{
|
||||
return $this->access_level === UserAccessLevel::TENANT_OWNER;
|
||||
}
|
||||
}
|
||||
|
||||
// {
|
||||
// "email": "master@services-core.local",
|
||||
// "password": "Master@12345"
|
||||
// }
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserMenuGroup extends Model
|
||||
{
|
||||
protected $table = 'user_menu_groups';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'menu_group_id',
|
||||
'tenant_id',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function menuGroup()
|
||||
{
|
||||
return $this->belongsTo(MenuGroup::class, 'menu_group_id');
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class, 'tenant_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserProfile extends Model
|
||||
{
|
||||
protected $table = 'user_profiles';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'nik',
|
||||
'address',
|
||||
'provinsi_id',
|
||||
'kabupaten_id',
|
||||
'kecamatan_id',
|
||||
'desa_id',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserTenant extends Model
|
||||
{
|
||||
protected $table = 'user_tenants';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'tenant_id',
|
||||
'is_default',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_default' => 'boolean',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class, 'tenant_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WilayahDesa extends Model
|
||||
{
|
||||
protected $table = 'wilayah_desa';
|
||||
|
||||
protected $fillable = ['kecamatan_id', 'kode', 'nama'];
|
||||
|
||||
public function kecamatan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WilayahKecamatan::class, 'kecamatan_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class WilayahKabupaten extends Model
|
||||
{
|
||||
protected $table = 'wilayah_kabupaten';
|
||||
|
||||
protected $fillable = ['provinsi_id', 'kode', 'nama'];
|
||||
|
||||
public function provinsi(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WilayahProvinsi::class, 'provinsi_id');
|
||||
}
|
||||
|
||||
public function kecamatan(): HasMany
|
||||
{
|
||||
return $this->hasMany(WilayahKecamatan::class, 'kabupaten_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class WilayahKecamatan extends Model
|
||||
{
|
||||
protected $table = 'wilayah_kecamatan';
|
||||
|
||||
protected $fillable = ['kabupaten_id', 'kode', 'nama'];
|
||||
|
||||
public function kabupaten(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WilayahKabupaten::class, 'kabupaten_id');
|
||||
}
|
||||
|
||||
public function desa(): HasMany
|
||||
{
|
||||
return $this->hasMany(WilayahDesa::class, 'kecamatan_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class WilayahProvinsi extends Model
|
||||
{
|
||||
protected $table = 'wilayah_provinsi';
|
||||
|
||||
protected $fillable = ['kode', 'nama'];
|
||||
|
||||
public function kabupaten(): HasMany
|
||||
{
|
||||
return $this->hasMany(WilayahKabupaten::class, 'provinsi_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user