简体   繁体   中英

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

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!

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM