feat: inisialisasi project kit v2
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class NotificationLog extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'body',
|
||||
'image_url',
|
||||
'deep_link',
|
||||
'target_type',
|
||||
'target_user_id',
|
||||
'sender_id',
|
||||
'status',
|
||||
'error_message',
|
||||
];
|
||||
|
||||
public function targetUser()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'target_user_id');
|
||||
}
|
||||
|
||||
public function sender()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'sender_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RemoteConfig extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'platform',
|
||||
'latest_version',
|
||||
'min_version',
|
||||
'maintenance_mode',
|
||||
'store_url',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'maintenance_mode' => 'boolean',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['key', 'value', 'type'];
|
||||
|
||||
/**
|
||||
* Get setting value by key, cast properly.
|
||||
*/
|
||||
public static function get(string $key, $default = null)
|
||||
{
|
||||
$setting = self::where('key', $key)->first();
|
||||
if (!$setting) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return match($setting->type) {
|
||||
'boolean' => filter_var($setting->value, FILTER_VALIDATE_BOOLEAN),
|
||||
'integer' => (int) $setting->value,
|
||||
'json' => json_decode($setting->value, true),
|
||||
default => $setting->value,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a setting value.
|
||||
*/
|
||||
public static function set(string $key, $value, string $type = 'string')
|
||||
{
|
||||
if (is_array($value)) {
|
||||
$value = json_encode($value);
|
||||
$type = 'json';
|
||||
} elseif (is_bool($value)) {
|
||||
$value = $value ? '1' : '0';
|
||||
$type = 'boolean';
|
||||
}
|
||||
|
||||
return self::updateOrCreate(
|
||||
['key' => $key],
|
||||
['value' => $value, 'type' => $type]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Laravel\Passport\HasApiTokens;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
use Spatie\Activitylog\Traits\LogsActivity;
|
||||
use Spatie\Activitylog\LogOptions;
|
||||
|
||||
#[Fillable(['first_name', 'last_name', 'email', 'phone', 'bio', 'password', 'status', 'avatar_url', 'meta', 'two_factor_secret', 'two_factor_recovery_codes', 'two_factor_confirmed_at'])]
|
||||
#[Hidden(['password', 'remember_token', 'two_factor_secret', 'two_factor_recovery_codes'])]
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable, HasRoles, SoftDeletes, LogsActivity, HasApiTokens;
|
||||
|
||||
public function getActivitylogOptions(): LogOptions
|
||||
{
|
||||
return LogOptions::defaults()
|
||||
->logFillable()
|
||||
->logOnlyDirty()
|
||||
->dontSubmitEmptyLogs();
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP 8.4 Property Hooks (Polyfill for PHP 8.3 environment)
|
||||
*/
|
||||
public function getFullName(): string
|
||||
{
|
||||
return "{$this->first_name} {$this->last_name}";
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->status === 'active' && !$this->deleted_at;
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP 8.4 Asymmetric Visibility (Polyfill)
|
||||
*/
|
||||
protected ?string $avatarUrl = null;
|
||||
|
||||
public function getAvatarUrl(): ?string
|
||||
{
|
||||
return $this->avatarUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'meta' => 'array',
|
||||
'status' => 'string',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync avatarUrl with avatar_url attribute.
|
||||
*/
|
||||
public function setAvatar(string $path): void
|
||||
{
|
||||
$this->avatar_url = $path;
|
||||
$this->avatarUrl = \Illuminate\Support\Facades\Storage::url($path);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user