Wednesday, February 28, 2018

Realtime validation using Laravel - development

Realtime validation using Laravel

I am using Laravel Framework and i’m new in this Framework. This scenario is my problem.

Scenario: User A review some of document once they click the “Edit” button (unlocked document), other user can’t review
that document because the system will be locked other user to review in the same time. I’ve got this.

But, the problem is, how can the system set once User A click “Edit” button, the time automatically running within in 4 hours.
When the time is finish, automatically review document of User A will be locked and “Edit” button will show to the other user.

This is example of the interface.
enter image description here

Here is my index.blade code

<td>
            <a title="View Detail" data-pjax="pjax-modal-container" type="button" class="btn btn-xs btn-info" href=""><i class="fa fa-eye"></i></a>
            @if($modelItemReviewReviewer->status_id==303)
            <a title="No Review" type="button" class="btn btn-xs btn-danger"><i class="fa fa-lock"></i></a>
            @elseif ($modelItemReview->lock_item==1 && $modelItemReviewReviewer->status_id==301)
            <a title="No Review" type="button" class="btn btn-xs btn-danger"><i class="fa fa-lock"></i></a>
            @elseif ($modelItemReview->lock_item==1 && $modelItemReviewReviewer->status_id==302)
            <a title="Can Review" type="button" class="btn btn-xs btn-primary"><i class="fa fa-unlock"></i></a>
            @else
            <a title="Can Review" type="button" class="btn btn-xs btn-primary"><i class="fa fa-unlock"></i></a>
            @endif
            @if($modelItemReviewReviewer->status_id==302 && ($modelItemReviewReviewer->upload_id != null || $modelItemReviewReviewer->remark != null))
            <a title="Submit Confirmation" data-pjax="pjax-modal-container" data-id="" type="button" class="btn btn-xs btn-success update_status"><i class="fa fa-check-circle"></i></a>
            @include('item_review_reviewer.modal_update_status')
            @endif
        </td>

And here is my controller:

public function show(Request $request, $id) {
    $modelItemReviewReviewer = ItemReviewReviewer::findOrFail($id);

    if ($modelItemReviewReviewer->status_id == 301 && $modelItemReview->lock_item == 2) {
        $modelItemReviewReviewer->status_id = 302; //Item on Review
        AppClassesAuditTrailHelper::logAuditUpdate("item_review_reviewers", $modelItemReviewReviewer->id, $modelItemReviewReviewer);
        $modelItemReviewReviewer->updated_by = Auth::user()->id;
        $modelItemReviewReviewer->save();

        $modelItemReview->lock_item = 1;
        AppClassesAuditTrailHelper::logAuditUpdate("item_reviews", $modelItemReview->id, $modelItemReview);
        $modelItemReview->updated_by = Auth::user()->id;
        $modelItemReview->save();
    }

    return view('index.blade', compact('modelItemReviewReviewer','modelItemReview','request'));
}

Can someone show me how it’s work ?



from Laravel Questions and Answers https://laravelquestions.com/laravel/realtime-validation-using-laravel/
via Lzo Media

No comments:

Post a Comment