- Laravel 11.51 + PHP 8.4 in backend/
- MySQL 9 connection (DBngin, db: verde)
- Installed Sanctum, Spatie permission/activitylog/model-states,
matanyadaev/laravel-eloquent-spatial
- API routes prefixed /api/v1 in bootstrap/app.php
- Standard response envelope { success, data, message, errors, meta }
via ApiResponse + ApiController base class
- Global exception handlers for validation/auth/not-found/http errors
on api/* routes (always JSON, never redirect to login)
- Extended users migration: uuid, phone+verified_at, role enum
(admin/resident/driver/helper/scanner/store_partner), status,
first/middle/last name, avatar_path, preferred_language, fcm_token,
last_login_at, soft deletes
- User model: HasApiTokens, HasRoles, LogsActivity, SoftDeletes,
role/status constants, auto-uuid on create
- Health endpoint at GET /api/v1/health verifies DB connection
- backend/CLAUDE.md documenting backend conventions
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
87 lines
2.3 KiB
PHP
87 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Str;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
use Spatie\Activitylog\LogOptions;
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<\Database\Factories\UserFactory> */
|
|
use HasApiTokens, HasFactory, HasRoles, LogsActivity, Notifiable, SoftDeletes;
|
|
|
|
public const ROLE_ADMIN = 'admin';
|
|
public const ROLE_RESIDENT = 'resident';
|
|
public const ROLE_DRIVER = 'driver';
|
|
public const ROLE_HELPER = 'helper';
|
|
public const ROLE_SCANNER = 'scanner';
|
|
public const ROLE_STORE_PARTNER = 'store_partner';
|
|
|
|
public const STATUS_ACTIVE = 'active';
|
|
public const STATUS_SUSPENDED = 'suspended';
|
|
public const STATUS_PENDING = 'pending';
|
|
|
|
protected $fillable = [
|
|
'uuid',
|
|
'email',
|
|
'phone',
|
|
'password',
|
|
'role',
|
|
'status',
|
|
'first_name',
|
|
'middle_name',
|
|
'last_name',
|
|
'avatar_path',
|
|
'preferred_language',
|
|
'fcm_token',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $user): void {
|
|
if (empty($user->uuid)) {
|
|
$user->uuid = (string) Str::uuid();
|
|
}
|
|
});
|
|
}
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'phone_verified_at' => 'datetime',
|
|
'last_login_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
];
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly(['email', 'phone', 'role', 'status', 'first_name', 'last_name'])
|
|
->logOnlyDirty()
|
|
->dontSubmitEmptyLogs();
|
|
}
|
|
|
|
public function getFullNameAttribute(): string
|
|
{
|
|
return trim(implode(' ', array_filter([
|
|
$this->first_name,
|
|
$this->middle_name,
|
|
$this->last_name,
|
|
])));
|
|
}
|
|
}
|