Websockets in Laravel – Part 2: Setting up Comments API & AJAX



We are all anxious to get writing some code to interact with websockets, but first we need to build the foundation of code necessary to start submitting and displaying comments to our users. Once we have this part setup, then we can easily add websockets to it to enhance the experience even more.

This episode will create a small API for us to interact with and will create some structure to save our comments.

First we need to create a database migration to store our comments. This will require creating a migration, a model, and a controller for our comments.

We will make 2 API endpoints for our comments. The first is to display all comments for a specific post. The second endpoint will allow us to save a new comment via the API.

Then its time to use this API by setting up our frontend. We will create two Vue.js methods to handle this. The first is getComments() which gets all the comments for the current post, and the second is postComments() which will post a new comment for the current post.

Next up: We actually connect websockets to display new comments onto the page as they are submitted live!

==== WRITTEN TUTORIALS ====

“Mastering Websockets in Laravel” Master Series Page:

Mastering Websockets with Laravel Echo

Part 2: Setting Up Comments AJAX (Written Tutorial)

Websockets in Laravel – Part 2: Creating Comments AJAX


==== MORE FROM THIS SERIES . ====

Full Playlist for the “Mastering Websockets in Laravel” Series:

==== DOWNLOAD SOURCE CODE ====

Github Code Repo for this Series:
https://github.com/DevMarketer/Laravel_Echo_Tutorial

Download Source Code for this Episode:
https://github.com/DevMarketer/Laravel_Echo_Tutorial/releases/tag/Part2

==== FOLLOW ME ====

Subscribe for New Releases!

Subscribe to DevMarketer Insider (Email)
https://confirmsubscription.com/h/d/5EDC91CF554832D1

Twitter – http://twitter.com/_jacurtis
(ask me questions!)

==== QUESTIONS? ====

Leave a comment below and I or someone else can help you.
For quick questions you may also want to ask me on Twitter, I respond almost immediately.

Email me hello@jacurtis.com

Thanks for all your support!

source

Reply

Do NOT follow this link or you will be banned from the site!