Init: Hoan thanh kien truc V3 va Filament UI

This commit is contained in:
2026-04-18 02:07:30 +00:00
commit 761b34916b
141 changed files with 15917 additions and 0 deletions

26
app/Models/Contract.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Contract extends Model
{
use HasUuids, HasFactory;
protected $guarded = [];
// 1 Hợp đồng thuộc về 1 Sản phẩm
public function product()
{
return $this->belongsTo(Product::class);
}
// 1 Hợp đồng có thể có nhiều Khách hàng (Đồng sở hữu)
public function customers()
{
return $this->belongsToMany(Customer::class, 'contract_customers')->withPivot('role', 'transfer_order')->withTimestamps();
}
}

27
app/Models/Customer.php Normal file
View File

@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Customer extends Model
{
use HasUuids, HasFactory;
protected $guarded = [];
// Ép kiểu để Laravel tự động dịch JSON thành Mảng khi hiển thị lên Form
protected $casts = [
'address' => 'array',
'dob' => 'date',
];
public function contracts()
{
return $this->belongsToMany(Contract::class, 'contract_customers')
->withPivot('role', 'transfer_order')
->withTimestamps();
}
}

31
app/Models/Product.php Normal file
View File

@@ -0,0 +1,31 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
use HasUuids, HasFactory;
protected $guarded = [];
// Ép kiểu JSON để Filament có thể đọc/ghi dữ liệu linh hoạt (tầng, hướng, mặt tiền...)
protected $casts = [
'custom_data' => 'array',
];
// Khai báo mối quan hệ V3: 1 Sản phẩm thuộc về 1 Dự án
public function project()
{
return $this->belongsTo(Project::class);
}
// Đón đầu cho các bước tiếp theo: 1 Sản phẩm có nhiều Hợp đồng
public function contracts()
{
return $this->hasMany(Contract::class);
}
}

20
app/Models/Project.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
use HasUuids, HasFactory;
protected $guarded = []; // Cho phép lưu tất cả các cột
// Khai báo mối quan hệ: 1 Dự án có nhiều Sản phẩm
public function products()
{
return $this->hasMany(Product::class);
}
}

32
app/Models/User.php Normal file
View File

@@ -0,0 +1,32 @@
<?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\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
#[Fillable(['name', 'email', 'password'])]
#[Hidden(['password', 'remember_token'])]
class User extends Authenticatable
{
/** @use HasFactory<UserFactory> */
use HasFactory, Notifiable;
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
}