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 =CarbonCarbon::parse($work->start_from)->format('d-m-Y h:i A');
$end =CarbonCarbon::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" class="btn btn-info btn-sm " data-toggle="modal"
data-target="#edit{{ $work->id }}"
title="{{ trans('Works_trans.Edit') }}"><i
class="fa fa-edit"></i>
</button>
@endcan
@can('delete_work')
<button type="button" class="btn btn-danger btn-sm " data-toggle="modal"
data-target="#delete{{ $work->id }}"
title="{{ trans('Works_trans.Delete') }}"><i
class="fa fa-trash"></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
2
Answers
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.
You have two consitions here:
What you want to do here is offcourse ignore the first condition and do this:
Check if
created_at
is not equal toupdated_at
disable edit button orcreated_ad
is more than 24 hours ago disable edit.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.