Add entry and exit time fields with duration calculation in VehicleEntryResource form
Some checks failed
Gemini PR Review / Gemini PR Review (pull_request) Waiting to run
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Waiting to run
Laravel Larastan / larastan (pull_request) Waiting to run
Laravel Pint / pint (pull_request) Waiting to run
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Gemini PR Review / Gemini PR Review (pull_request) Waiting to run
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Waiting to run
Laravel Larastan / larastan (pull_request) Waiting to run
Laravel Pint / pint (pull_request) Waiting to run
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Filament\Resources\VehicleEntryResource\Pages;
|
||||
use App\Filament\Resources\VehicleEntryResource\RelationManagers;
|
||||
use App\Models\Plant;
|
||||
use App\Models\VehicleEntry;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
@@ -40,12 +41,36 @@ class VehicleEntryResource extends Resource
|
||||
->required(),
|
||||
Forms\Components\DateTimePicker::make('entry_time')
|
||||
->label('Entry Time')
|
||||
->required(),
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, callable $get, callable $set) {
|
||||
$exitTime = $get('exit_time');
|
||||
|
||||
if ($state && $exitTime) {
|
||||
$duration = Carbon::parse($exitTime)
|
||||
->diff(Carbon::parse($state))
|
||||
->format('%H:%I:%S');
|
||||
|
||||
$set('duration', $duration);
|
||||
}
|
||||
}),
|
||||
Forms\Components\DateTimePicker::make('exit_time')
|
||||
->label('Exit Time')
|
||||
->required(),
|
||||
->required()
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $get, callable $set) {
|
||||
$entryTime = $get('entry_time');
|
||||
|
||||
if ($state && $entryTime) {
|
||||
$duration = Carbon::parse($state)
|
||||
->diff(Carbon::parse($entryTime))
|
||||
->format('%H:%I:%S');
|
||||
|
||||
$set('duration', $duration);
|
||||
}
|
||||
}),
|
||||
Forms\Components\TextInput::make('duration')
|
||||
->label('Duration')
|
||||
->readOnly()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('type')
|
||||
->label('Type')
|
||||
|
||||
Reference in New Issue
Block a user