I want to disbale button for specific work for next 24 hours when that user click that button. also i want user can't edit any thing after 24 hours 24 hours.
<?php $i = 0; ?>
@foreach ($works as $work)
@php
$start =Carbon\Carbon::parse($work->start_from)->format('d-m-Y h:i A');
$end =Carbon\Carbon::parse($work->end_to)->format('d-m-Y h:i A');
$t1 = strtotime($start);
$t2 = strtotime($end);
$total = gmdate('h:i',$t2 - $t1);
$oneHourDiff = now()->addDays(-1);
@endphp
<tr>
<?php $i ; ?>
<td>{{ $i }}</td>
<td>{{$start}}</td>
<td>{{$end}}</td>
<td>{{$total}}</td>
<td>{{$work->project->Name}}</td>
<td>{{ $work->description }}</td>
@if(isset($work->user->name))
<td>{{$work->user->name}}</td>
@else
<td>--</td>
@endif
<td>
@can('edit_work')
<button type="button" data-toggle="modal"
data-target="#edit{{ $work->id }}"
title="{{ trans('Works_trans.Edit') }}"><i
></i>
</button>
@endcan
@can('delete_work')
<button type="button" data-toggle="modal"
data-target="#delete{{ $work->id }}"
title="{{ trans('Works_trans.Delete') }}"><i
></i></button>
@endcan
</td>
</tr>
@endforeach
I want to disbale button for specific work for next after 24 hour when that user click that button. also i want user can't edit any thing after 24 hour
CodePudding user response:
If you have the updated_at
column in your database table, then you can get the last updated time from that column and compare it with the current time. So, if it is less than 24 hours, then you can disable it.
If you have multiple users, you will have to create an additional table, to keep a record of the edited time and the user ID. From that table, compare the time and enable/disable the buttons.
CodePudding user response:
You have two consitions here:
- Disable once edited (for 24 hours)
- Do not edit once 24 hours have passed.
What you want to do here is offcourse ignore the first condition and do this:
Check if created_at
is not equal to updated_at
disable edit button or created_ad
is more than 24 hours ago disable edit.
$created_at = Carbon::create($record->created_at);
$now = Carbon::now();
$time_passed = $now->diffInHours($created_at);
if($record->created_at != $record->updated_at || $time_passed > 24){
//Disable the edit button
//...
}
These 2 conditions will make sure the record does not get edit twice as well as editing is disabled after 24 hours. So basically you are allowing to edit only once and in first 24 hours only.