I want to implement web notifications in Laravel using web sockets. I have
tried pusher. It is very easy but it is a paid package. I have also tried redis and socket.io for which I have to install horizon. I am running Windows and I cannot install it on Windows according to what I have read about horizon.
So I am very confused about push notification. I am trying for at least one week but haven't found any solution yet. My front end is in angluar 5/android and backend is in Laravel 5.6.
Can you please suggest me any good ideas to implement push notification?
You have been use pusher,so I assume you know how to use event.
I recommend you laravel-echo-server.It's very easy to use,with a built-in api.
Here is a fresh example of a laravel-echo project from scratch.
After you set up the project.
you will need predis if you haven't install it yet
composer require predis/predis
redis-server /usr/local/etc/redis.conf
run npm install -g laravel-echo-server
run laravel-echo-server init
uncomment App\Providers\BroadcastServiceProvider::class in config/app.php
add <script src="https://cdn.jsdelivr.net/npm/socket.io-client#2.1.1/dist/socket.io.js"></script> in your app.blade.php
you need a socketio-client ,you can run npm install --save laravel-echo .In case you are not familiar with npm or vue, you can simply include this compiled file from my github project.compiledjs
add this to app.blade.php
<script>
window.Echo = new Echo({
broadcaster: 'socket.io',
host: '{{url('/').':6001'}}',
});
Echo.private(`App.User.{{Auth::id()}}`) // private channel
.listen('NewMessage', (e) => {
console.log(e)
});
</script>
finally run laravel-echo-server start and open you project ,you will see
[20:53:21] - Lv5OKDAcuSLsK1nBAAAE authenticated for: private-
App.User.1
[20:53:21] - Lv5OKDAcuSLsK1nBAAAE joined channel: private-App.User.1
you can listen any event you want or other notifications
here is my github project echo-example
add a little code so that you can use postman send message to specfic user.You can see the message from chrome console.You can get more details from github project screenshots
Take a look at this article. It covers implementing websocket in laravel using redis driver, Laravel echo and socket.io client.
According to above article:
“Why don’t you just use Pusher?”
Here is the thing.
Laravel comes with Pusher enabled. Even though Pusher seems like a quick “Plug and play” solution (which it is), it comes with limitations. Check https://pusher.com/pricing
And most of the tutorials trick you with their title of implementing Websockets when in reality they just want to give you Pusher. (And my favorite part is when they say that you can easily switch to socket.io)
As per laravel documentation, I will recommend using Pusher. I have created a package for to user WebSockets in laravel.
https://www.techzonemind.com/scalable-websocket-server-laravel-applications/
It will use Redis for background queuing to optimize performance. I have used it in few solutions. I may not be usable in all use cases. But good to have a look.
PHP not build to execute concurrent tasks, if you have a choice, nodejs will be a better solution,
THE BEST WAY TO INTEGRATE REALTIME IN LARAVEL IS NIETHER NODE NOR PUSHER
You find Pusher Easier and you don't want to pay the price . Then without hesitation you should try Laravel Websockets . Its a very simple Pusher Replacement .
In Short You use the pusher client libs to access a pusher like server that is hosted in your php server . Since its open source its free .
Its better than using socket.io or redis because they require you to pay additional
server costs .
You can check their demo app here
PS
If you want more custom controls then you can use ratchet
Related
So I tried creating a new project using Breeze+vue in Laravel.
I was following this guide: https://www.youtube.com/watch?v=A7UlfXPhsaA
When I finally got vite running on npm run dev without issues, I came across the app_url and I tried to change it to something similar like in that guide (timestamp 6:14 in video), in my case the app_url value was just http://localhost and I changed it to http://grandia.test.
And it reflects like that when vite is running:
VITE v3.1.0 ready in 1031 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
LARAVEL v9.28.0 plugin v0.6.0
➜ APP_URL: http://grandia.test
but nothing happens when I go to the site. only the localhost:5173 works properly.
I tried googling for answers but I couldn't find anything helpful.
Could someone help me out what I'm doing wrong or missing? Thanks!
I had the same issue, It look like you changed URL: http://grandia.test instead of localhost. So you should try with npm run build instead.
Changing Laravel’s APP_URL parameter will not magically allow you to choose the URL your website is served at. It will only tell Laravel what it should use when generating URLs related to your website.
The video’s author uses the Laravel Valet local development environment. It provides a park command that allows you to automatically serve the subfolders of some folder (e.g. Sites in the video) at http://<subfolder>.test.
In the video, the project is created in Sites/reddit-clone/, which makes it possible to directly access it at reddit-clone.test.
I run my laravel app #localhost.
```php artisan serve --host=localhostIP```
On top I run an Andoid app with the same base URL.
Could anyone tell me how can I debug incoming API´s calls
like if BASEURL/users is called?
Furthermore, how can I log the happening events in the console
I am developing API's with laravel too, i do it this way:
composer require laravel/homestead to have it all in a vm 😉 see https://laravel.com/docs/master/homestead for more information, i use the "per project" installation
Download postman to have the best tool for sending querys to your api and to test your api quick -> https://www.getpostman.com (i use it free)
configure and run your homestead (it's not that complicated).
your homestead is fit with php and xdebug enabled
i am using phpStorm and have my vagrant setup as deployment target
"listen to debug" with phpstorm
to your GET requests, add a queryparam XDEBUG_SESSION_START=PHPSTORM
i can debug my api now 😉
i also wrote https://logcrawler.de to receive the log informations of all my api's and all my server 🤩
I hope, i could help you a little bit
This is my way, but I think it's not good!
Create router api in config/web, Eg:
router/api: Route::post('/check_api', [CheckController::class, 'testFunc'])->name('api.check_api');
web/api: Route::post('test/check_api', [CheckController::class, 'testFunc'])->name('test.check_api');
Create a post by form or ajax in one resource/view like index
Go to page, and debug with phpstorm
You can use logging feature of Laravel. Apply Logs on entry point of application to test whether API url is hitting or not.
use postman
https://www.getpostman.com/downloads/
it's an excellent thing very much usefull
When I use Postman to send or get data to/from my local Laravel applications it always returns the error...
Could not get any response.
For example, a GET request to
http://demo_app.localhost/api/data.
I use Laravel Valet on my Mac. It looks like Postman can't find the local domain.
I had the same issue when trying to use valet with Postman and what fixed it for me was turning off the SSL verification in Settings > General. I believe valet is using some internal SSL certificate by default that cannot be verified properly by Postman.
Use TLD .test, if your Valet version is up-to-date and not specifically configured to use .localhost.
Should be like http://demo_app.test/api/data
See official docs for background:
Valet documentation at chapter "Using Another Domain".
I had the same issue and used all the suggestion above, none of them works.
For my case, I used the following command to fix the problem:
php artisan optimize
This clears the cache and config files and reloads the new api Routes added to the Laravel framework.
I have made a simple backend with feathersjs for testing purposes.
For mobile application I am using nativescript with (angular 5). But one of the feathersjs client library require socketio-client.
socket.io-client library fails in nativescript.
So I used following nativescript plugins ( none of them works with featherSocketIOClient )
nativescript-socket.io
nativescript-socketio
Please help.
You do not have to use Feathers on the client to connect to a Feathers server.
refer to the documentation
Basically what the title says ;).
I've seen an npm package for Express (https://www.npmjs.org/package/heroku-ssl-redirect), but not for MeteorJS.
Assuming you have configured SSL this package should come handy
meteor add force-ssl
It worked on 0.9.4, I'm not sure it's working now