Undefined property: App\Http\Controllers\PostController::$p

1.8k views Asked by At

my controller look like

 public function react(Request $request){
        //echo "hi";
        //return;
        //return response()->json($request);
        $this->validate($request, [
            'postid' => 'required',
            'react' => 'required'
        ]);
        $reaction = Reaction::firstOrNew([
            'post_id'=>$request->postid,
            'user_id'=> Auth::id()
        ]);
        $reaction->user_id = Auth::id();
        $reaction->type = $request->react;
        $reactType = "";
        if ($request->react === "l"){$reactType = "liked";}
        else if ($request->react === "d"){$reactType = "disliked";}
        else if ($request->react === "h"){$reactType = "loved";}
        else if ($request->react === "s"){$reactType = "Smiled";}
        else{}



        $post = Post::find($request->postid);
        $postuser = $post->user->name;

        if($post->reactions()->save($reaction)){
            $data['message'] = Auth::user()->name.' '.$reactType. ' a Post from' . $postuser;
            $data['type'] = 'reaction';
            **$this->p->trigger('user-'.$post->user_id, 'new-post', $data);**
            return response()->json([
                'success' => true,
                'message' => 'Reacted'
            ]);
        }
        else{
            return response()->json([
                'success' => false,
                'message' => 'Error'
            ]);
        }

AND I AM UNABLE TO LINK WITH PUSHER CHANNEL But I keep getting an error

Undefined property: App\Http\Controllers\MyController::$p

What am I doing wrong? Would highly appreciate any possible help!

1

There are 1 answers

0
Akbar Rahmanii On

property $this->p (p) , You have not set the value

$this->p = Value ;

After setting, you can use the information.

$this->p->trigger('user-'.$post->user_id, 'new-post', $data);

In the code written above, $this->p has an null value

$this->null->trigger('user-'.$post->user_id, 'new-post', $data);

In fact, this is how you use it