Create socket for laravel and vuejs - laravel

I wrote the backend with Laravel as an api and the front with vueJs, of course, are completely separate.
Now I want to create notifications for some tasks.
I do not want to use the pusher and I want to create the socket myself (to practice and understand how it works).
Now my question is, do I have to create a separate socket for both Back and Front and connect both of them to the same port?
Thankful.

you can use the laravel-echo on the client-side and use the laravel-echo-server on the server-side.
at the first, you should install and configure the laravel-echo-serve then run it in your server.
now for client-side, install the laravel-echo and listen to your custom port which you defined in laravel-echo-serve config.
And for call your socket, just enough create an event in your laravel project and create an instance like below and place it in your desired location:
event(new App/Events/ExampleEvent());

Related

How to send notification to specific user in Expo/Laravel

I have an Expo app with a Laravel backend and I want to send notifications to the app. But the condition is that only a specific user can receive it.
I installed the Following library Exponent Notifications
I've Installed expo-notifications as well
But I don't know How it works, How I can listen to the notification channel and How to send Notification from backend.
With Expo you don't get to pick the push notification service according to you, you can try Firebase Cloud messaging or One Signal, but I don't think you can do it only by your Laravel Backend

Laravel - Checking for a new messages with websocket

I built my first app in Laravel and I am wondering what is the best way to check for a new messages while you are in conversation with someone? This is how conversation looks now: http://prntscr.com/t976tx .
I want to check for a new message without reloading a page and constantly listening that event.
I was reading about Socket.io and I have no idea how to start with that..i am using Laravel 5.7

Is there anyway to do simple laravel notification

Is there anyway to make laravel notification in a simple way? I need to do notification function for my complaint handling system where the system should notify the user if complaint exist in their account which should be User Id.
You can make a pusher like system with redis, node.js and socket.io
You have a tutorial in Medium

Where to subscribe for Redis Pub/Sub in Laravel?

I've been using Redis's Pub/Sub a bit in my application and so far it has been great. I am able to send out a Publish out of Laravel to a different backend process that is able to Subscribe, and eventually Publish an event back to Laravel.
The use case for the user looks like:
submit a form -> wait for a response (a few minutes) -> proceed with transaction
On the backend:
the form posts to a route, then to a controller that publishes this to a subscribed 3rd party (channel one), and eventually that 3rd party publishes back (channel two)
Main Issue: I don't know where the appropriate place to be for subscribing to the (channel two) and processing what gets published there.
Ideally, I'd be able to process Publish requests in two ways:
Letting the user know that their form has been processed and they can move onto the next step (probably with an update to a property a Vue component)
Storing information from the publish into my database.
In the docs, they have it in a Command, which if I try to use here would look like so:
public function handle()
{
Redis::subscribe('channel-two', function ($message) {
// update the client so that the user moves on
// send $message contents to the database
});
}
but that doesn't really seem ideal for me since I want this channel subscribed to 24/7, always listening. Even if it is in a Command, it is still apparent how I would best update the client.
Where in my Laravel project should I be subscribing at? Is there a best practice to respond to these events?
Redis::subscribe is used in a command like in that example for listening on a given channel continuously.
From the docs:
First, let's setup a channel listener using the subscribe method. We'll place this method call within an Artisan command since calling the subscribe method begins a long-running process:
You'll want to run the command using a process manager like supervisor or pm2, much the same as the docs describe running queue listeners.

How to listen for presence on Laravel 5.4 backend?

Is there are some way to listen for presence channel on backend, not frontend? For example i want to execute some database operations when user joinin or leaving the channel?

Resources