Updated validations on Importer and Resource file
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
This commit is contained in:
@@ -19,6 +19,8 @@ use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
// use Illuminate\Validation\Rule;
|
||||
|
||||
class PlantResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Plant::class;
|
||||
@@ -42,18 +44,21 @@ class PlantResource extends Resource
|
||||
->reactive()
|
||||
->placeholder('Scan the valid code')
|
||||
->autofocus(true)
|
||||
// ->minLength(4)
|
||||
// ->maxLength(7)
|
||||
->minValue(1000)
|
||||
->maxValue(9999999)
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$codeId = $get('code');
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$codeId) {
|
||||
if (! $codeId) {
|
||||
$set('pCodeError', 'Scan the valid code.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strlen($codeId) < 4) {
|
||||
$set('pCodeError', 'Code must be at least 4 digits.');
|
||||
} else {
|
||||
if (strlen($codeId) < 4 || strlen($codeId) > 7) {
|
||||
$set('pCodeError', 'Code must be between 4 and 7 digits only!'); // Code must be at least 4 digits.
|
||||
|
||||
return;
|
||||
}
|
||||
// if (!preg_match('/^[1-9][0-9]{3,}$/', $codeId)) {
|
||||
@@ -64,6 +69,9 @@ class PlantResource extends Resource
|
||||
$set('pCodeError', null);
|
||||
}
|
||||
})
|
||||
// ->rule(function (callable $get) {
|
||||
// return Rule::unique('plants', 'code')->ignore($get('id'));
|
||||
// })
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('pCodeError') ? 'border-red-500' : '',
|
||||
])
|
||||
@@ -77,16 +85,15 @@ class PlantResource extends Resource
|
||||
->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) {
|
||||
$companyId = $get('company_id');
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$companyId) {
|
||||
if (! $companyId) {
|
||||
$set('pCompanyError', 'Please select a company first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('pCompanyError', null);
|
||||
}
|
||||
})
|
||||
@@ -101,18 +108,21 @@ class PlantResource extends Resource
|
||||
->unique(ignoreRecord: true)
|
||||
->columnSpanFull()
|
||||
->reactive()
|
||||
->minLength(5)
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$nameId = $get('name');
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$nameId) {
|
||||
if (! $nameId) {
|
||||
$set('pNameError', 'Scan the valid name.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('pNameError', null);
|
||||
}
|
||||
})
|
||||
// ->rule(function (callable $get) {
|
||||
// return Rule::unique('plants', 'name')->ignore($get('id'));
|
||||
// })
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('pNameError') ? 'border-red-500' : '',
|
||||
])
|
||||
@@ -124,15 +134,15 @@ class PlantResource extends Resource
|
||||
->unique(ignoreRecord: true)
|
||||
->columnSpanFull()
|
||||
->reactive()
|
||||
->minLength(5)
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$nameId = $get('address');
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$nameId) {
|
||||
if (! $nameId) {
|
||||
$set('pAddressError', 'Scan the valid address.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('pAddressError', null);
|
||||
}
|
||||
})
|
||||
@@ -159,6 +169,7 @@ class PlantResource extends Resource
|
||||
$paginator = $livewire->getTableRecords();
|
||||
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
||||
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
||||
|
||||
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||
})
|
||||
->toggleable(isToggledHiddenByDefault: false),
|
||||
@@ -225,14 +236,14 @@ class PlantResource extends Resource
|
||||
->label('Import Plants')
|
||||
->color('warning')
|
||||
->importer(PlantImporter::class)
|
||||
->visible(function() {
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view import plant');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->label('Export Plants')
|
||||
->color('warning')
|
||||
->exporter(PlantExporter::class)
|
||||
->visible(function() {
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view export plant');
|
||||
}),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user