我们都急于编写一些代码来与Websocket交互,但是首先我们需要建立必要的代码基础,以开始向用户提交和显示评论。设置好零件后,我们可以轻松地向其中添加Websocket,以进一步增强体验。
这一集将创建一个供我们与之交互的小型API,并将创建一些结构来保存我们的评论。
首先,我们需要创建数据库迁移来存储我们的注释。这将需要为我们的注释创建迁移,模型和控制器。
我们将为注释添加2个API端点。第一种是显示特定帖子的所有评论。第二个端点将允许我们通过API保存新评论。
然后通过设置前端来使用此API。我们将创建两个Vue.js方法来处理此问题。第一个是getComments(),它获取当前帖子的所有评论,第二个是postComments(),它将为当前帖子发布一个新评论。
下一步:实际上,我们连接了Websocket,以便在实时提交新评论时将其显示在页面上!
====书面教学====
“掌握Laravel中的Websockets”大师系列页面:
第2部分:设置注释AJAX(书面教程)
====这一系列的更多内容。 ====
“掌握Laravel中的Websocket”系列的完整播放列表:
====下载源代码====
该系列的Github代码仓库:
https://github.com/DevMarketer/Laravel_Echo_Tutorial
下载此剧集的源代码:
https://github.com/DevMarketer/Laravel_Echo_Tutorial/releases/tag/Part2
====跟我来====
订阅新版本!
订阅DevMarketer Insider(电子邮件)
https://confirmsubscription.com/h/d/5EDC91CF554832D1
Twitter-http://twitter.com/_jacurtis
(问我问题!)
====问题? ====
在下面发表评论,我或其他人可以为您提供帮助。
对于快速问题,您可能还想在Twitter上问我,我几乎立即做出回应。
给我发电子邮件[email protected]
感谢您的支持! 。
Im getting empty object in comments, does any one have a solution for that
Stop using freaking pusher… its freaking everywhere and its a paid service. I'm whatching your other video "Self-Host your Own websocket"
why iam getting internal server error GET http://localhost:8000/api/posts/1/comments 500 (Internal Server Error).. in router/api same and commentController index same with your.. but still error
does anyone know how to edit or delete a specific comment?
In the store method of CommentController where you fetch the comment the from database again using with user, we can instead just use $comment->load('user'); and it will eager load the user. Thanks very much for this great detailed tutorial.
i want to know how to deploy on web serve
When calling event on controller then Unknown auth_key broadcastExeption Error. Plz help
if you got 404 not found error. then use full url in axios.get function. like this.
axios.get('/echo/public/api/posts/'+this.post.id+'/comments')
you are too slow man…
I would like to advise you to make short length tutorials and kindly check after a few lines of code so if a view is watching he/she does not have to go back to the beginning of the tutorial to check where they have made a mistake.
You are just copying code, please try to explain it as well when you write some code from somewhere else
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 🙂
Alex, thank you so much for your work and for the video! Really cool, you explain everything very available and understandably.
great Instructor, big info and clear code, and save too much time to learn, really you are super instructor
can you give me a video about how to send ajax request through api layer rest full api with jquery and laravel?
if you have an error with post in /api/posts/${this.post.id}/comment, see the video where he explains about api_token, the video is called "Laravel API Token Authentication and Model Observers (Ep 23) – Build an Advanced Blog & CMS0" https://www.youtube.com/watch?v=Ym5_8f-tMzc
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?
Thanks for the websockets tutorials man, i really appriciate it! Big Thanks you are a good man!
Thank u very much sir
I have some little problem , when I save a comment it is giving 500 error code in network and there written that the problem is with mass assignment though I have the same code as yours. What should I do to solve this problem?
whoooow …. look im writing vue…. mindblowen
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?
Тамаша! Өте қызықты әрі түсінікті! Сәттілік!
Excellent video and explanation of using Vue.
16:02
Vue.js devtools for Firefox <3
https://addons.mozilla.org/en-US/firefox/addon/vue-js-devtools/
echo.test is not working, I configured vhosts, databases and other required fields as administrator. someone please help..
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!
Gracias por el tutorial, pero hablas demaciado.
you can use $comment->load('user') instead of line 22 (14:50)