[英]App\Http\Controllers\PostController` is not invokable:
[英]Undefined property: App\Http\Controllers\PostController::$p
我的控制器看起來像
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'
]);
}
而且我無法與 PUSHER CHANNEL 鏈接但我不斷收到錯誤消息
未定義的屬性:App\\Http\\Controllers\\MyController::$p
我究竟做錯了什么? 非常感謝任何可能的幫助!
我的控制器看起來像
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'
]);
}
而且我無法與推銷渠道建立聯系,但我不斷收到錯誤消息
未定義的屬性:App \\ Http \\ Controllers \\ MyController :: $ p
我究竟做錯了什么? 非常感謝您提供任何可能的幫助!
屬性$this->p
(p) ,你還沒有設置值
$this->p = Value ;
設置后,您可以使用該信息。
$this->p->trigger('user-'.$post->user_id, 'new-post', $data);
在上面寫的代碼中, $this->p
有一個空值
$this->null->trigger('user-'.$post->user_id, 'new-post', $data);
事實上,這就是你如何使用它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.