0

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;
}

asad sajjad
  • 85
  • 2
  • 12

1 Answers1

0

I have fixed it again ... here was the error

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

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

needed to put the policy on untick condition, I was putting it before it.

asad sajjad
  • 85
  • 2
  • 12