mercredi 31 août 2016

trying ticking off the check box twice unticks it where it shouldnt untick the checkbox until the user who ticked or the admin laravel

Only the user who ticked the checkbox can untick the checkbox or the admin can do it but when I try unticking it with any other user then it unticks it on SECOND attemp but on first attempt it stays ticked.

My controller File

public function tickoffUpload($id, $type, User $user) {

    $uploads = $this->upload->get($id); //gets upload id

    if($this->request->isMethod('get')) {
        if($user->can('untick', $uploads) || (Auth::user()->role=='admin')) {
            if($type == 0) {
                $uploads->uploaded = $this->request->upload = 1;

            } else if($type == 1) {
                $uploads->uploaded = $this->request->upload = 0;  

            }

        } else {
            $uploads->uploaded = 1;
         }

    }

    return redirect('/home');

}

User Policy

public function untick(User $user, Upload $upload) { return Auth::id() == $upload->user_id;
}




Aucun commentaire:

Enregistrer un commentaire