[FEAT] 客戶管理欄位(客戶代號、起始日)非必填化

1. 新增遷移檔將 companies.code 改為 nullable 並增加長度至 100,解決刪除時字串過長的問題。
2. 修改 CompanyController 驗證邏輯,允許 code 與 start_date 為空。
3. 更新前端公司管理頁面,移除 code 與 start_date 的必填限制與 UI 標記。
This commit is contained in:
sky121113 2026-05-15 17:02:59 +08:00
parent cfaa8dfe54
commit 2f550839cc
3 changed files with 36 additions and 8 deletions

View File

@ -48,13 +48,13 @@ class CompanyController extends Controller
{
$validated = $request->validate([
'name' => 'required|string|max:255',
'code' => 'required|string|max:50|unique:companies,code',
'code' => 'nullable|string|max:50|unique:companies,code',
'original_type' => 'required|string|in:buyout,lease',
'tax_id' => 'nullable|string|max:50',
'contact_name' => 'nullable|string|max:255',
'contact_phone' => 'nullable|string|max:50',
'contact_email' => 'nullable|email|max:255',
'start_date' => 'required|date',
'start_date' => 'nullable|date',
'end_date' => 'nullable|date',
'warranty_start_date' => 'nullable|date',
'warranty_end_date' => 'nullable|date',
@ -158,13 +158,13 @@ class CompanyController extends Controller
{
$validated = $request->validate([
'name' => 'required|string|max:255',
'code' => 'required|string|max:50|unique:companies,code,' . $company->id,
'code' => 'nullable|string|max:50|unique:companies,code,' . $company->id,
'current_type' => 'required|string|in:buyout,lease',
'tax_id' => 'nullable|string|max:50',
'contact_name' => 'nullable|string|max:255',
'contact_phone' => 'nullable|string|max:50',
'contact_email' => 'nullable|email|max:255',
'start_date' => 'required|date',
'start_date' => 'nullable|date',
'end_date' => 'nullable|date',
'warranty_start_date' => 'nullable|date',
'warranty_end_date' => 'nullable|date',

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('companies', function (Blueprint $table) {
$table->string('code', 100)->nullable()->change();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('companies', function (Blueprint $table) {
$table->string('code', 20)->nullable(false)->change();
});
}
};

View File

@ -795,8 +795,8 @@
</div>
<div class="space-y-2">
<label class="text-xs font-black text-slate-500 uppercase tracking-widest pl-1">{{
__('Company Code') }} <span class="text-rose-500 ml-0.5">*</span></label>
<input type="text" name="code" x-model="currentCompany.code" required
__('Company Code') }}</label>
<input type="text" name="code" x-model="currentCompany.code"
class="luxury-input w-full" placeholder="{{ __('e.g. TWSTAR') }}">
</div>
</div>
@ -811,8 +811,8 @@
<div class="grid grid-cols-2 gap-3" x-show="currentCompany.current_type === 'lease'">
<div class="space-y-2">
<label class="text-xs font-black text-slate-500 uppercase tracking-widest pl-1">{{
__('Start Date') }} <span class="text-rose-500 ml-0.5">*</span></label>
<input type="date" name="start_date" x-model="currentCompany.start_date" :required="currentCompany.current_type === 'lease'"
__('Start Date') }}</label>
<input type="date" name="start_date" x-model="currentCompany.start_date"
class="luxury-input w-full px-2">
</div>
<div class="space-y-2">