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

preview_player
Показать описание
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.

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:

Part 2: Setting Up Comments AJAX (Written Tutorial)
==== MORE FROM THIS SERIES . ====

Full Playlist for the "Mastering Websockets in Laravel" Series:

==== DOWNLOAD SOURCE CODE ====

Github Code Repo for this Series:

Download Source Code for this Episode:

==== FOLLOW ME ====

Subscribe for New Releases!

Subscribe to DevMarketer Insider (Email)

(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.

Thanks for all your support!
Рекомендации по теме
Комментарии
Автор

You make the slightly complicated stuff look and sound easy and they actually turn out to be. Thanks for the simple vocabulary.

ephsonguakro
Автор

you can use $comment->load('user') instead of line 22 (14:50)

ojdgaf
Автор

great Instructor, big info and clear code, and save too much time to learn, really you are super instructor

ashrafsaleh
Автор

Awesome!!! "Meraviglioso Tutorial"

francescochiriaco
Автор

Alex, thank you so much for your work and for the video! Really cool, you explain everything very available and understandably.

StAsMaNnX
Автор

I have a small question if you dont mind, what is better, to write the vue script inside the blade like you are doing here or write it in seperate component file? Seems easier to do it in blade since you get easy access to laravel data instead of having to make api calls for everything from the component, but this way youre making the code itself public right? which way is generally used in production?

zamphox
Автор

Thanks for the websockets tutorials man, i really appriciate it! Big Thanks you are a good man!

Slavv
Автор

Great Tutorial! I am wondering why one can post the api_key through axios and laravel knows, which user to save the comment to. At what point does laravel do the check for that? I can only see the body and user id in the mass assignment where the api_key is not mentioned at all 🤔.

Thanks for this great series!

sebastianjung
Автор

So in the show.blade.php by using the @{{ }} syntax that lets you use Vue directives instead of blade?

Ribby
Автор

i'm so new to this
so is it possible to do the commenting part without vu
like using ajax without vu
sorry if my question is little dummy :)

ahmedyah
Автор

Awesome tutorial, although I encounter an error: basically vue inspector cannot find any Vue component. even in network tab Vue.js is not pulled into the application. Any idea? I also tried to run npm run development again :S....with not results. I would appreciate any help with this! thanks :)

enricoalbertocerri
Автор

I get only curly braces at comment {{comment.user.name}} ..
when I installed vue extension for chrome, it says "vue.js not detected"
I also added the cdn script tag inside app.blade.php . What can be the problem?

wahsher
Автор

wow ... awesome teacher & awesome tutorial

codeology
Автор

Very good videos for everyone to learn

buacomgiadinh
Автор

whoooow .... look im writing vue.... mindblowen

MeerTheKat
Автор

Hi, bro...

Do you have more contents for 2022?

TrikNgonlen
Автор

Alex thanks for great tutorials, I am a newbie to Laravel and I learnt a lot with you! I just have a problem, I can not load the comments to a posts. It returns an error post 403(Forbidden)
Thanks again!

marioibarra
Автор

It would be wonderful if you will make another tutorial for multiple posts in a single page.

iandaleblanco
Автор

Is this tutorial still viable with Laravel 7? Can you still get user api_token and submit a comment the way you did?

jamesikubi
Автор

can you give me a video about how to send ajax request through api layer rest full api with jquery and laravel?

ToeurTenh
welcome to shbcf.ru