skip to Main Content

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 enter image description here24 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


  1. 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.

    Login or Signup to reply.
  2. You have two consitions here:

    1. Disable once edited (for 24 hours)
    2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search