We want to count the duration between two different date fields on a database. Can anyone help convert this SQL query to a database migration in Laravel?
CREATE TABLE api_incident_duration
(START DATETIME, END DATETIME, elapsed DECIMAL(5, 2)
AS (ROUND(TIMESTAMPDIFF(MINUTE, START, END) / 60, 2)));
Perhaps:
$table->dateTime('startdatetimepicker')->nullable();
$table->dateTime('enddatetimepicker')->nullable();
$table->decimal('elapsed', 5, 2)
->virtualAs(ROUND(TIMESTAMPDIFF(MINUTE, startdatetimepicker, enddatetimepicker) / 60, 2));