lundi 11 juin 2018

Query returning every row null in laravel

I'm trying to build a chat application using laravel echo and pusher, everything works but the data that returns to the databse is either null or the default value, here's the code

  public function sendMessage(Request $request){
  $conID = $request->conID;
  $message1 = $request->message;
  $user = Auth::user();

  $fetch_userTo = DB::table('messages')
  ->where('conversation_id', $conID)
  ->where('user_to', '!=', Auth::user()->id)
  ->get();
  $userTo = $fetch_userTo[0]->user_to;

  $message = Message::create([
    'user_from' => Auth::user()->id,
    'user_to' => $userTo,
    'conversation_id' => $conID,
    'message' => $message1,
    ]);

    if($message) {
      $userMsg = DB::table('messages')
      ->join('users', 'users.id','messages.user_from')
      ->where('messages.conversation_id', $conID)->get();

      broadcast(new MessagePosted($message))->toOthers();
      return $userMsg;
    }
}   

NB: when i put insert() instead of create in the query the data goes through the database normally but there's an error in broadcasting



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire