Postingan lainnya
Masalah tidak bisa post id group ke table message
aku lagi bikin chat pake Framework Laravel, Vue.js dan Pusher, singkat cerita aku sudah bisa nampilin nama groupnya dan get data messagenya di kolom chat, masalahnya saat di post pesannya malah group_id nya undefined
get message
Route::get('/groups/{groupId}', function($groupId) {
$authUserId = Auth::user()->id;
$output = DB::table('messages')
->leftJoin('users','users.id', '=', 'messages.user_id')
->join('groups','groups.id','=','messages.group_id')
->where('messages.user_id','=',$authUserId)
->where('messages.group_id','=',$groupId)
->orWhere('messages.user_id','!=',$authUserId)
->where('messages.group_id','=',$groupId)
->select('users.name as user','users.image','users.image_path','users.id as userId','groups.id as groupId','messages.message','messages.file_path','messages.file_name','messages.type','messages.created_at as time')
->orderBy("messages.id","asc")
->get();
return $output;
})->middleware('auth');
utk post ke table message
Route::post('/groups/{groupId}', function($groupId) {
$user = Auth::user();
$message = $user->messages()->create([
'message'=>request()->get('message'),
'type'=>request()->get('type'),
'group_id'=>$groupId,
]);
// new message has beed posted
broadcast(new MessagePosted($message,$user,$groupId))->toOthers();
$output['message'] = $message;
$output['user'] = $user;
return ['output'=> $output];
})->middleware('auth');
0
2 Jawaban:
Ini post pakai ajax ya gan. Coba cek di url ajax nya, kayanya ketinggalan tuh groupId nya.
0