Added combined unique and default value
This commit is contained in:
@@ -15,6 +15,7 @@ use Filament\Tables\Table;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
use Filament\Forms\Components\Section;
|
use Filament\Forms\Components\Section;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
class BlockResource extends Resource
|
class BlockResource extends Resource
|
||||||
{
|
{
|
||||||
@@ -34,7 +35,7 @@ class BlockResource extends Resource
|
|||||||
->schema([
|
->schema([
|
||||||
Forms\Components\TextInput::make('name')
|
Forms\Components\TextInput::make('name')
|
||||||
->required()
|
->required()
|
||||||
->unique(ignoreRecord: true)
|
// ->unique(ignoreRecord: true)
|
||||||
->placeholder('Scan the valid name')
|
->placeholder('Scan the valid name')
|
||||||
->autofocus(true)
|
->autofocus(true)
|
||||||
->reactive()
|
->reactive()
|
||||||
@@ -54,12 +55,20 @@ class BlockResource extends Resource
|
|||||||
'class' => $get('bNameError') ? 'border-red-500' : '',
|
'class' => $get('bNameError') ? 'border-red-500' : '',
|
||||||
])
|
])
|
||||||
->hint(fn ($get) => $get('bNameError') ? $get('bNameError') : null)
|
->hint(fn ($get) => $get('bNameError') ? $get('bNameError') : null)
|
||||||
->hintColor('danger'),
|
->hintColor('danger')
|
||||||
|
->rule(function (callable $get) {
|
||||||
|
return Rule::unique('blocks', 'name')
|
||||||
|
->where('plant_id', $get('plant_id'))
|
||||||
|
->ignore($get('id')); // Ignore current record during updates
|
||||||
|
}),
|
||||||
Forms\Components\Select::make('plant_id')
|
Forms\Components\Select::make('plant_id')
|
||||||
->relationship('plant', 'name')
|
->relationship('plant', 'name')
|
||||||
// ->unique(ignoreRecord: true)
|
// ->unique(ignoreRecord: true)
|
||||||
->required()
|
->required()
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->default(function () {
|
||||||
|
return optional(Block::latest()->first())->plant_id;
|
||||||
|
})
|
||||||
->disabled(fn (Get $get) => !empty($get('id')))
|
->disabled(fn (Get $get) => !empty($get('id')))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$nameId = $get('plant_id');
|
$nameId = $get('plant_id');
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use Filament\Tables\Table;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
use Filament\Forms\Components\Section;
|
use Filament\Forms\Components\Section;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
class ItemResource extends Resource
|
class ItemResource extends Resource
|
||||||
{
|
{
|
||||||
@@ -41,6 +42,9 @@ class ItemResource extends Resource
|
|||||||
// ->preload()
|
// ->preload()
|
||||||
// ->nullable(),
|
// ->nullable(),
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->default(function () {
|
||||||
|
return optional(Item::latest()->first())->plant_id;
|
||||||
|
})
|
||||||
->disabled(fn (Get $get) => !empty($get('id')))
|
->disabled(fn (Get $get) => !empty($get('id')))
|
||||||
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
|
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
@@ -64,7 +68,7 @@ class ItemResource extends Resource
|
|||||||
->required()
|
->required()
|
||||||
->placeholder('Scan the valid code')
|
->placeholder('Scan the valid code')
|
||||||
->autofocus(true)
|
->autofocus(true)
|
||||||
->unique(ignoreRecord: true)
|
// ->unique(ignoreRecord: true)
|
||||||
->alphaNum()
|
->alphaNum()
|
||||||
->minLength(6)
|
->minLength(6)
|
||||||
// ->autocapitalize('characters')
|
// ->autocapitalize('characters')
|
||||||
@@ -95,7 +99,12 @@ class ItemResource extends Resource
|
|||||||
'class' => $get('iCodeError') ? 'border-red-500' : '',
|
'class' => $get('iCodeError') ? 'border-red-500' : '',
|
||||||
])
|
])
|
||||||
->hint(fn ($get) => $get('iCodeError') ? $get('iCodeError') : null)
|
->hint(fn ($get) => $get('iCodeError') ? $get('iCodeError') : null)
|
||||||
->hintColor('danger'),
|
->hintColor('danger')
|
||||||
|
->rule(function (callable $get) {
|
||||||
|
return Rule::unique('items', 'code')
|
||||||
|
->where('plant_id', $get('plant_id'))
|
||||||
|
->ignore($get('id')); // Ignore current record during updates
|
||||||
|
}),
|
||||||
Forms\Components\TextInput::make('hourly_quantity')
|
Forms\Components\TextInput::make('hourly_quantity')
|
||||||
->required()
|
->required()
|
||||||
->label('Hourly Quantity')
|
->label('Hourly Quantity')
|
||||||
@@ -183,7 +192,8 @@ class ItemResource extends Resource
|
|||||||
])
|
])
|
||||||
->headerActions([
|
->headerActions([
|
||||||
ImportAction::make()
|
ImportAction::make()
|
||||||
->importer(ItemImporter::class),
|
->importer(ItemImporter::class)
|
||||||
|
->maxRows(100000),
|
||||||
ExportAction::make()
|
ExportAction::make()
|
||||||
->exporter(ItemExporter::class),
|
->exporter(ItemExporter::class),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use Filament\Tables\Table;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
use Filament\Forms\Components\Section;
|
use Filament\Forms\Components\Section;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\Rules\Unique;
|
use Illuminate\Validation\Rules\Unique;
|
||||||
|
|
||||||
class LineResource extends Resource
|
class LineResource extends Resource
|
||||||
@@ -38,6 +39,9 @@ class LineResource extends Resource
|
|||||||
->required()
|
->required()
|
||||||
// ->nullable(),
|
// ->nullable(),
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->default(function () {
|
||||||
|
return optional(Line::latest()->first())->plant_id;
|
||||||
|
})
|
||||||
->disabled(fn (Get $get) => !empty($get('id')))
|
->disabled(fn (Get $get) => !empty($get('id')))
|
||||||
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
|
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
@@ -88,16 +92,16 @@ class LineResource extends Resource
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$exists = Line::where('name', $lineNam)
|
// $exists = Line::where('name', $lineNam)
|
||||||
->where('plant_id', $get('plant_id'))
|
// ->where('plant_id', $get('plant_id'))
|
||||||
->exists();
|
// ->exists();
|
||||||
|
|
||||||
if ($exists) {
|
// if ($exists) {
|
||||||
$set('name', null);
|
// $set('name', null);
|
||||||
$set('lNameError', 'The name has already been taken.');
|
// $set('lNameError', 'The name has already been taken.');
|
||||||
// $set('lNameError', 'The combination of name and plant ID must be unique.');
|
// // $set('lNameError', 'The combination of name and plant ID must be unique.');
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
$set('lNameError', null);
|
$set('lNameError', null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -105,7 +109,12 @@ class LineResource extends Resource
|
|||||||
'class' => $get('lNameError') ? 'border-red-500' : '',
|
'class' => $get('lNameError') ? 'border-red-500' : '',
|
||||||
])
|
])
|
||||||
->hint(fn ($get) => $get('lNameError') ? $get('lNameError') : null)
|
->hint(fn ($get) => $get('lNameError') ? $get('lNameError') : null)
|
||||||
->hintColor('danger'),
|
->hintColor('danger')
|
||||||
|
->rule(function (callable $get) {
|
||||||
|
return Rule::unique('lines', 'name')
|
||||||
|
->where('plant_id', $get('plant_id'))
|
||||||
|
->ignore($get('id')); // Ignore current record during updates
|
||||||
|
}),
|
||||||
Forms\Components\TextInput::make('type')
|
Forms\Components\TextInput::make('type')
|
||||||
->required()
|
->required()
|
||||||
->placeholder('Scan the valid type')
|
->placeholder('Scan the valid type')
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ class PlantResource extends Resource
|
|||||||
->relationship('company', 'name')
|
->relationship('company', 'name')
|
||||||
->required()
|
->required()
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->default(function () {
|
||||||
|
return optional(Plant::latest()->first())->company_id;
|
||||||
|
})
|
||||||
->disabled(fn (Get $get) => !empty($get('id')))
|
->disabled(fn (Get $get) => !empty($get('id')))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$companyId = $get('company_id');
|
$companyId = $get('company_id');
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Filament\Resources;
|
|||||||
|
|
||||||
use App\Filament\Imports\ShiftImporter;
|
use App\Filament\Imports\ShiftImporter;
|
||||||
use App\Filament\Resources\ShiftResource\Pages;
|
use App\Filament\Resources\ShiftResource\Pages;
|
||||||
|
use App\Models\Plant;
|
||||||
use App\Models\Shift;
|
use App\Models\Shift;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
@@ -16,6 +17,7 @@ use Filament\Tables\Table;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
use Filament\Forms\Components\Section;
|
use Filament\Forms\Components\Section;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
class ShiftResource extends Resource
|
class ShiftResource extends Resource
|
||||||
{
|
{
|
||||||
@@ -38,6 +40,9 @@ class ShiftResource extends Resource
|
|||||||
->required()
|
->required()
|
||||||
// ->nullable()
|
// ->nullable()
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->default(function () {
|
||||||
|
return optional(Shift::latest()->first())->plant_id;
|
||||||
|
})
|
||||||
->disabled(fn (Get $get) => !empty($get('id')))
|
->disabled(fn (Get $get) => !empty($get('id')))
|
||||||
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
|
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
@@ -62,6 +67,9 @@ class ShiftResource extends Resource
|
|||||||
->required()
|
->required()
|
||||||
// ->nullable()
|
// ->nullable()
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->default(function () {
|
||||||
|
return optional(Shift::latest()->first())->block_id;
|
||||||
|
})
|
||||||
->disabled(fn (Get $get) => !empty($get('id')))
|
->disabled(fn (Get $get) => !empty($get('id')))
|
||||||
// ->options(fn (callable $get) =>
|
// ->options(fn (callable $get) =>
|
||||||
// \App\Models\Block::where('plant_id', $get('plant_id'))
|
// \App\Models\Block::where('plant_id', $get('plant_id'))
|
||||||
@@ -109,17 +117,17 @@ class ShiftResource extends Resource
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$exists = Shift::where('plant_id', $get('plant_id'))
|
// $exists = Shift::where('plant_id', $get('plant_id'))
|
||||||
->where('block_id', $get('block_id'))
|
// ->where('block_id', $get('block_id'))
|
||||||
->where('name', $nameId)
|
// ->where('name', $nameId)
|
||||||
->latest()
|
// ->latest()
|
||||||
->exists();
|
// ->exists();
|
||||||
if ($exists)
|
// if ($exists)
|
||||||
{
|
// {
|
||||||
$set('start_time', null);
|
// $set('start_time', null);
|
||||||
$set('sNameError', 'Scanned name already exist.');
|
// $set('sNameError', 'Scanned name already exist.');
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
$set('sNameError', null);
|
$set('sNameError', null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -127,7 +135,13 @@ class ShiftResource extends Resource
|
|||||||
'class' => $get('sNameError') ? 'border-red-500' : '',
|
'class' => $get('sNameError') ? 'border-red-500' : '',
|
||||||
])
|
])
|
||||||
->hint(fn ($get) => $get('sNameError') ? $get('sNameError') : null)
|
->hint(fn ($get) => $get('sNameError') ? $get('sNameError') : null)
|
||||||
->hintColor('danger'),
|
->hintColor('danger')
|
||||||
|
->rule(function (callable $get) {
|
||||||
|
return Rule::unique('shifts', 'name')
|
||||||
|
->where('plant_id', $get('plant_id'))
|
||||||
|
->where('block_id', $get('block_id'))
|
||||||
|
->ignore($get('id')); // Ignore current record during updates
|
||||||
|
}),
|
||||||
Forms\Components\TimePicker::make('start_time')
|
Forms\Components\TimePicker::make('start_time')
|
||||||
->required()
|
->required()
|
||||||
->label('Start Time')
|
->label('Start Time')
|
||||||
@@ -146,18 +160,18 @@ class ShiftResource extends Resource
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$exists = Shift::where('plant_id', $get('plant_id'))
|
// $exists = Shift::where('plant_id', $get('plant_id'))
|
||||||
->where('block_id', $get('block_id'))
|
// ->where('block_id', $get('block_id'))
|
||||||
->where('name', $get('name'))
|
// ->where('name', $get('name'))
|
||||||
->latest()
|
// ->latest()
|
||||||
->exists();
|
// ->exists();
|
||||||
if ($exists)
|
// if ($exists)
|
||||||
{
|
// {
|
||||||
$set('start_time', null);
|
// $set('start_time', null);
|
||||||
$set('sStartTimeError', null);
|
// $set('sStartTimeError', null);
|
||||||
$set('sNameError', 'Scanned name already exist.');
|
// $set('sNameError', 'Scanned name already exist.');
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
$set('sStartTimeError', null);
|
$set('sStartTimeError', null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
0
storage/app/.gitignore
vendored
Normal file → Executable file
0
storage/app/.gitignore
vendored
Normal file → Executable file
0
storage/app/private/.gitignore
vendored
Normal file → Executable file
0
storage/app/private/.gitignore
vendored
Normal file → Executable file
0
storage/framework/.gitignore
vendored
Normal file → Executable file
0
storage/framework/.gitignore
vendored
Normal file → Executable file
0
storage/framework/cache/.gitignore
vendored
Normal file → Executable file
0
storage/framework/cache/.gitignore
vendored
Normal file → Executable file
0
storage/framework/cache/data/.gitignore
vendored
Normal file → Executable file
0
storage/framework/cache/data/.gitignore
vendored
Normal file → Executable file
0
storage/framework/sessions/.gitignore
vendored
Normal file → Executable file
0
storage/framework/sessions/.gitignore
vendored
Normal file → Executable file
0
storage/framework/testing/.gitignore
vendored
Normal file → Executable file
0
storage/framework/testing/.gitignore
vendored
Normal file → Executable file
0
storage/framework/views/.gitignore
vendored
Normal file → Executable file
0
storage/framework/views/.gitignore
vendored
Normal file → Executable file
0
storage/logs/.gitignore
vendored
Normal file → Executable file
0
storage/logs/.gitignore
vendored
Normal file → Executable file
Reference in New Issue
Block a user