Laravel - Send email on specific event - laravel

I am currently developing an API, and each click is counted, with an api consumption.
When 80% of the api is consumed, I would like to send an email alert to the user.
I don't know this whole aspect of Laravel yet, and I'd like to know how you would do that? If possible by detailing a minimum
Thank you in advance,

I assume that this information is available in your database.
If so, you could
make an artisan command which get all user with > 80% and
notified = 0
Loop on those user and send the mail
Set notified to 1 on each user
Use CRON & Laravel scheduler to call your command
Don't forget to reset "notified" if necessary

Related

fastest way to send notification to all user laravel

I am building an app in laravel where I send a mail notification to all users once a new channel I create. So far I am using
$users=User::all();
\Illuminate\Support\Facades\Notification::send($users,new NewChannel($channel));
To send a notification to all users. Is there any package or way that would make the process faster? It is already taking years just with 5 users
You can look into queues to make the request more responsive, though it will take the same time to process the mails but it will happen in background. Another approach would be to use a third party service like sendGrid to take away the processing from your end.

Laravel : Web Api, how to find out if a user (application) is online?

I am building a web service for mobile application by Laravel 5.8. I need to get the location of online users, search on some properties and send a notification to them.
The problem is I can't find out if a user is online. My solution was to keep pushing/receiving a message to applications every 10 seconds once they get connected for the first time. Clearly this approach has a huge overload on the server and is not practical.
I would be appreciated for any help.
Thanks in advance.
Sounds like you may make use of Real-time connections such as Pusher
You would need presence channels to see who is online in JS, it works more client to client rather than the Laravel server knowing who is online.
You subscribe users to a channel and then you can see who else is on that channel.
https://laravel.com/docs/5.8/broadcasting#presence-channels
Why not make a column to your user table namely 'is_online' ? So every time the user logged in set this field to true ? and when they are logged out or inactive for a specific of time you will set it to false ?

How to add a dynamic results section to Laravel

I made a laravel app which uses an index method that delivers a collection of the client's available appointments (think hairdresser) to the page (as an api), which I then display using vue/vuetify.
The client is saying they would like the appointments on the page to be dynamic/live eg if someone books an appointment, then all other logged in users will see that appointment disappear from the list on their screen.
I have no idea how I would do this, although I have had one idea - I somehow incorporate node/non-blocking on the server, like a chat room, but only for this part of the app.
Or is there a way to do this with laravel/nginx?
Thanks in advance - I don't know what to search for!
I believe you are looking for Broadcasting (Documentation Link). You would need to:
Configure your broadcasting driver (you could give pusher a try for quick setup and tinkering)
Configure your Laravel backend to dispatch a new event whenever a new appointment is made, (e.g. event(new AppointmentCreated($appointment)) where AppointmentCreated implements the ShouldBroadcast interface. You can combine this with Model Events
Update your frontend to receive your broadcast (Check Laravel Echo). Once you receive a broadcast, update the UI to mark this appointment as unavailable i.e, make it disappear

Slack logon trigger

I want to create something in Slack that sends a message (starting by calling someone with '#') to a channel when specific users login. I've checked ifttt and zapier. I also checked the slack api to create something myself, but I couldn't really find anything usefull.
Anyone has any ideas?
Slack does not track user login or logoff in a traditional sense. Instead, users are always always "logged in" and available to receive messages once they have joined a team / channel.
There also is the concept of "presence", which is related, but not the same thing. User presence can change multiple times during a few minutes, e.g. if the user is on a mobile. I am guessing you would not want to send the user your message that often.
Still you can poll the presence information of a user with the API users.getPresence , which could be used to implement a script that polls this information on a regular basis and send your message. You also want to filter out presence changes below a certain duration threshold.
Keep in mind though that the rate limit for API methods is 1 per second. So depending on how many users you have in your workspace there will be a significant delay between the user becoming "present" and your script being able to send the message.
There is a workaround for that to have a google sheet as a database for the users and you can trigger by day once and timestamp it.
So the best trigger is a private message or public and you can use filter when mentioning or signin or signout it depends on the trigger word then you pass the filter since zapier won't count your zaps if you used fiter as a second step.

How to run in background Laravel 5

Sending email with Laravel takes time before it is successfully sent, or sometimes it even fails. For this reason I would like to store record in database first and running email sending in background to save user's time. After storing the record, I would like to quickly redirect / refresh the page.
How do I use queue in below email sending code?
$message = new Applyonline($post_title, $cand_name);
$message->attachData($pdf->output(), $attach_name);
Mail::to($to_email)->send($message);
Please advise how to achieve this.
You can use Laravel Queues for this use the following link for complete explanation
Queue Thorough Explaination
I suggest looking into queues. Implementing this is quite easy. Just setup a queue for sending the mail and then add the queue to the mail facade. i.e Mail::to()->queue(new MailQueue);
Queues
Queueing mail

Resources