I build chat with laravel & vue js & pusher it's worked correctly but i host this project and i have this problem when a try ato add new message
/chat/ 403 (Forbidden)
This my confic in broadcasting.php
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' =>true,
'useTLS' => false,
],
],
File bootstrap.js
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
encrypted:true,
// forceTLS: true
});
enter code here
This my event file source
public function broadcastOn()
{
return new PrivateChannel('chat.'.$this->message->ticket_id);
}
public function broadcastAs()
{
return 'new.message';
}
Route channel
Broadcast::channel('chat.{ticket_id}', function ($user, $ticket_id) {
if(Auth::check()){
return ['id'=>$user->id,'name'=>$user->name];
}
});
this is my method for add new message in backend
public function store(Request $request)
{
$success = Message::create([
'message' => $request->message,
'user_id' => $request->user_id ,
'ticket_id' => $request->ticket_id ,
]);
broadcast(new NewChatMessage($success))->toOthers();
if($success){
$messages = Ticket::where('id',$request->ticket_id)
->with('messages',function($query){
$query->orderBy('created_at','ASC');
$query->with('user');
})
->first();
return $messages->messages;
}
}
This my method in frontend
addComment(id){
if(this.messages[0]){
this.newComment.ticket_id = this.messages[0].ticket_id
this.newComment.user_id = id;
axios.post('/chat',this.newComment)
.then((res)=>{
this.newComment = {}
})
.catch(err=>console.log(err))}
}
},
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire