Livewire generic polymorph comments in Laravel

Опубликовано: 23 Август 2021
на канале: Просто о Laravel. CutCode
1,235
50

What are generic polymorph comments in Laravel and how to do them correctly using Livewire. Universal comments can be used in any section of the site.
laraveltraining # laravel # cutcode

-------------------------------------------------- -------------------------------
❗️❗️❗️How to make complex sites in laravel? It's easy with cutcode!
Support my project - https://cutcode.ru/

Buy me coffee - buymeacoffee.com/cutcode

🤖🤖🤖My assistant Taylor is ready to give you a present. Pick up here - https://cutcode.ru/chat-bot

-------------------------------------------------- -------------------------------
⏰ Timecodes:
00:00 Introduction
01:08 Install livewire
01:34 Working with the model
03:22 Edit posts model
05:30 Create a livewire comment component
06:40 Setting up the comment view of the livewire component
09:50 Create add method for new comments
12:40 Output of livewire component with comments
13:40 Running migration
15:00 Bug fix with dynamic comment display
-------------------------------------------------- -------------------------------

Friends, I welcome everyone to the CutCode channel and today we have an interesting video. We'll be working with livewire and making generic comments.

Comments that can be easily applied in any section of your site. They will be polymorphic, that is, they will work with any model. As a basis, we will again take our project from the Laravel courses from scratch. We have posts and comments here. The comments are done in a simple way. We will now redo them and make them using livewire and, plus, work with polymorphic links in the models.

Let's get started right away. Also, I have already installed livewire from scratch on this platform from the laravel course. Those who follow the videos further and have not yet installed them here, you can watch the video on my channel on how to install the livewire. There is nothing complicated here, just add the livewire library via composer, I have already added it. And then just add styles and scripts.

Returning to our model, here we specify the filable property to indicate which fields can be filled in this model. This will be the user_id with the user who left the comment and, accordingly, the comment itself. Next, you need to add a method to make this model polymorphic. Why is commentable how this field was named before the underscore in our case, commentable is how the method should be called.

Here we specify commentable and here we return the morph_to method, that is, we have a polymorphic model and it will refer to any one model. There can be several of these models and they can change just what I explained to you in the commentable type field. So then we will also add a link to the user, it will be useful to us if we display the name of the one who left the comment. Here we return a value and specify the user class. We are done with the comment2 model itself. Next, we will need to specify which models we will have to refer to this model comment2.



-------------------------------------------------- -------------------------------
📹 share this video with your friends:
   • Livewire универсальные polymorph комм...  
🔔 subscribe to the YouTube channel:    / @cutcoderu  

Livewire generic polymorph comments in Laravel

-------------------------------------------------- -------------------------------
🔗 our website: https://cutcode.ru/
📷 our instagram:   / cutcoderu  


Смотрите видео Livewire generic polymorph comments in Laravel онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Просто о Laravel. CutCode 23 Август 2021, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1,235 раз и оно понравилось 50 людям.