Laravel Blog: Comments, Global Search, Deployment | Part 3 — Transcript
Full transcript
- 0:00what's up everybody the coaches here and
- 0:02welcome to my channel this is the third
- 0:04part of series building laravel 10 blog
- 0:06website and in this video we're gonna
- 0:08build comment sections so we're going to
- 0:10implement the entire comment section
- 0:12such as reading comments editing
- 0:14deleting writing child comments replying
- 0:17comments and even have like a deep
- 0:19nested level of replying comments we're
- 0:22gonna also Implement Global search on
- 0:25the website on the blog website to
- 0:27search for articles by title and a
- 0:29description and finally in this video
- 0:32we're going to deploy the project on
- 0:34custom domain and production environment
- 0:36with SSL certificate as well as a choice
- 0:38of Hosting provider for this tutorial
- 0:40I'm going to use hostinger which is also
- 0:42kindly sponsoring this video
- 0:44I have been using customer services for
- 0:47about two years and I can honestly say
- 0:49that it's one of the best shared hosting
- 0:51providers out there they support
- 0:53different type of Hosting such as shared
- 0:55hosting Cloud hosting VPS hosting but in
- 0:58my opinion their shared hosting services
- 1:01are just the best okay let's have a look
- 1:04at the website in just three dollar
- 1:06price they include the following things
- 1:09so they have 100 websites they have free
- 1:12domain which by itself costs at least 10
- 1:15you have unlimited free SSL certificates
- 1:18you have a possibility for free email
- 1:21and not only one email multiple emails
- 1:24you have like unlimited databases and
- 1:27there are many many other things in this
- 1:30uh like a three dollar shared housing
- 1:32plan so if we just click let's click
- 1:36this is actually Four dollar which is a
- 1:39business web hosting which is the most
- 1:41popular one but if we just click A2 card
- 1:44here and use the coupon code the code
- 1:47holique you're going to get additional
- 1:5010 discount on all that so you can
- 1:53choose period like one month 12 months
- 1:5524 or 48 months the more time period you
- 1:57choose obviously saving will be much
- 2:00more and as you can see like this is a
- 2:03four-yard hosting provider like the most
- 2:06common one probably is one yard because
- 2:08the domain also renews in one year so if
- 2:12we just click on 12 months we're going
- 2:14to see that we just pay
- 2:1648 48 dollar which includes domain as
- 2:20well as one year hosting and again if
- 2:23you use coupon code the code holy crate
- 2:26here you're gonna get additional 10
- 2:28discount
- 2:31decide to deploy this project or any
- 2:33other project on shared hosting I really
- 2:35recommend hostinger whenever you sign up
- 2:37you will be redirected to hostinger
- 2:39Modern Age panel and then the deployment
- 2:42part will be continued from there which
- 2:44will be the last part of this particular
- 2:46section and thank you hostinger for
- 2:49sponsoring this video all right now
- 2:51let's focus on the video and start
- 2:53building comment section
- 2:54okay let's bring up the terminal and I'm
- 2:56going to generate comments comment model
- 2:59PHP art design make model
- 3:04comment
- 3:05let's specify migration as well
- 3:08now let's open migration create comments
- 3:12table
- 3:12okay what do we need here
- 3:15obviously we need a string which will be
- 3:18comment
- 3:19we can make this comment very large so
- 3:22we can specify it can be text or even
- 3:25maybe a long text let's do long text
- 3:29and the name will be actual comment
- 3:33okay we obviously need post ID so let's
- 3:37specify foreign ID
- 3:40post ID
- 3:42that cannot be null so
- 3:45we should not specify nullable but it
- 3:48should be constrained on posts I'm going
- 3:51to duplicate this and specify the user
- 3:54ID that cannot be also now it must be
- 3:57provided and then we have constraint so
- 4:00we have uh time when the comment was
- 4:03actually made the comment can be deleted
- 4:05or updated whenever comment is deleted
- 4:07like we can Implement soft deletes
- 4:11and we can make it to be uh actually
- 4:14saved in the database which is kind of
- 4:16good thing and we should probably even
- 4:18be doing this for uh posts and articles
- 4:20which I'm not going to do this at this
- 4:23stage but again a great challenge to add
- 4:27soft deletes to your posts and comments
- 4:30and categories as well so that whenever
- 4:31comment is deleted and someone is
- 4:34blaming someone else you you can check
- 4:36in the database that the actual comment
- 4:39was presented there okay so we have uh
- 4:42post ID a user ID what else we might
- 4:46need uncomment
- 4:48like I think this is enough for the
- 4:49beginning we can of course add
- 4:51additional columns if that becomes
- 4:53necessary but at the moment we will know
- 4:55who made a comment on which posts he
- 4:59made a comment at what time and what's
- 5:02the actual common text
- 5:04that basically describes the whole
- 5:07common thing okay now let's open comment
- 5:10model
- 5:12and a defeatable
- 5:15we need to define those three columns
- 5:21that's perfect
- 5:28okay now we can start working on the
- 5:31design side let's actually run this
- 5:33migration PHP Artisan migrate
- 5:36oops something's wrong PHP Artisan
- 5:39migrate let's have a look what's the
- 5:42problem
- 5:44host views
- 5:51create post views table okay I think I
- 5:54have
- 5:55um just messed up something
- 5:57in my migration create post views so the
- 6:00post reviews table actually exists in my
- 6:02case but this is not marked in
- 6:03migrations again I messed up between
- 6:06recording sections which is
- 6:09which is okay
- 6:12so this is the post fuse which I'm gonna
- 6:15put this rate
- 6:17right here
- 6:21okay
- 6:24that's not going to be case
- 6:26on your machine
- 6:28okay now create comments table was
- 6:30successfully applied
- 6:31perfect let's close migrations common
- 6:34stable was created now I'm going to do
- 6:36comments using Live Wire
- 6:41so let's define components for live y
- 6:46we need comment section
- 6:48at the very bottom somewhere right here
- 6:53after next and
- 6:55yeah below next so let's create Live
- 6:59Wire components PHP artisan make
- 7:03Live Wire and we need to call the
- 7:06component
- 7:08let's call this comments
- 7:12okay let's hit the enter
- 7:14okay comments component was created here
- 7:16we see the comments blade as well
- 7:20I want to also
- 7:22maybe Define comment item
- 7:26so let's execute that comment item
- 7:31here we go let's hit the enter okay that
- 7:34was also created
- 7:35now what I have in my mind is that right
- 7:39here I'm going to have Commons section
- 7:41inside which I'm going to iterate and
- 7:43render comment items
- 7:46and then we're going to have of course
- 7:48like reply
- 7:50um or leave a comment section and things
- 7:53like that
- 7:54so I think we need to create
- 7:58[Music]
- 7:58um
- 7:59comment create
- 8:02comment create component as well
- 8:06and let's start with simple steps I'm
- 8:08going to open comment
- 8:10comment
- 8:12create
- 8:14okay this uses the following component
- 8:17let's actually
- 8:19have a look in this component I'm going
- 8:21to just write
- 8:23texts
- 8:25comment create
- 8:28I'm going to also open Commons blade
- 8:32okay so here we are going to iterate and
- 8:37I'm going to open comment item as well
- 8:38so in the comments blade we are going to
- 8:41iterate
- 8:42iterate and render
- 8:45comment items and then we're going to
- 8:48have comment create so let's actually
- 8:52use
- 8:54Live Wire
- 8:56colon comment slash create
- 9:00okay and this comments component needs
- 9:03to be used in The View Post View
- 9:07so let's collapse everything and I think
- 9:10this is the previous and next buttons
- 9:12and below that we can use Live Wire
- 9:17colon
- 9:18comments
- 9:20and that's it in the comments obviously
- 9:22will need post component so we can
- 9:25provide that here as well
- 9:28okay so we save this reload the page and
- 9:31we see right here iterate and render
- 9:33comment items and then we have comment
- 9:35create this is in the set Center which I
- 9:39don't expected it to be in the center
- 9:42and maybe this is in the center because
- 9:46we have right here Flex column and item
- 9:49Center if we just remove this item
- 9:51Center
- 9:53I think we will not have and everything
- 9:55else will stay the same which is perfect
- 9:58now let's start working on the comment
- 10:01create
- 10:03so here we obviously need input
- 10:07then we need whenever we click inside
- 10:11the input we need to be able to write
- 10:13some sort of comment so let's start with
- 10:15the input and we're gonna of course add
- 10:17additional HTML we will need one button
- 10:20which will be to
- 10:22um
- 10:23submit maybe and another button
- 10:27which will be to cancel
- 10:30okay let's do like this so this let's
- 10:35provide some classes like um we need
- 10:38let me actually grab those classes from
- 10:43Talon CSS not to type them
- 10:45every time so this is a button
- 10:48yeah I want a normal button
- 11:01um okay I don't want to like expend too
- 11:04much time on typing uh tolerances
- 11:07classes
- 11:09so let me actually try to do this if I
- 11:13do it
- 11:14in a short time that's fine so
- 11:17ax3 I want let's give it a PG
- 11:23PG blue
- 11:24uh 400 and on Hover we need PG blue
- 11:30um maybe 600 or specify 500 here let's
- 11:35give these rounded as well and text
- 11:38White
- 11:40all right let's give this one
- 11:45um
- 11:46leave a comment
- 11:49okay perfect
- 11:50let's have a look so we see leave a
- 11:52comment we see submit and cancel
- 11:55all right so this leave a comment
- 11:57section needs to be in some div element
- 11:59so that it needs to be on the whole line
- 12:01we need to install input components
- 12:05actually there is this uh Tailwind
- 12:10components free components package
- 12:14telling the UI
- 12:16okay and if we go in the browse
- 12:18components
- 12:21and choose any of those components
- 12:23especially I'm interested in the forms
- 12:25because we need an input like contact
- 12:27Section for example
- 12:29so this is it and I'm going to go in the
- 12:31code I see that I need to install Talon
- 12:34CSS forms
- 12:35and I think I I don't have that
- 12:37installed so I'm going to bring up the
- 12:39terminal and execute npm install
- 12:43Talon CSS forms
- 12:45and I'm going to also open
- 12:49shift
- 12:52tailwind config.js and in plugins yeah I
- 12:57already had Talon CSS forms which is
- 13:01good
- 13:02and I'm going to grab the classes for
- 13:06that specific form like the first name
- 13:08for example let me actually grab this
- 13:10form
- 13:12and I'm going to put this right here
- 13:16let's format the code we have a huge
- 13:21huge CSS
- 13:24and let me try to
- 13:27wrap
- 13:30I want soft wraps to enable soft drops
- 13:38appearance
- 13:45I generally don't enable this part for
- 13:47tutorials that's um that's something
- 13:50necessary
- 13:51use soft wrap
- 13:56I want this to be enabled on probably
- 13:58every file
- 14:00soft crops
- 14:02yeah that's it okay now we see all the
- 14:05classes every time so that's fine so I
- 14:08save this and have a look so we have
- 14:10this input we can provide right here
- 14:12lace holder leave a comment and to have
- 14:17all this consistency I'm going to grab
- 14:20button
- 14:22let's talk buttons tiles from here as
- 14:25well let's
- 14:27talk so let's get this button and put
- 14:31this right here
- 14:35okay and instead of let's talk we'll
- 14:38give it a name submit
- 14:41I'm going to duplicate now these
- 14:44and instead of type submit
- 14:47I'm going to just remove that or maybe
- 14:50it should be a type pattern because by
- 14:52default it's already submit let's give
- 14:54it class cancel
- 14:58and we obviously need different styles
- 15:00right here so I'm going to remove
- 15:02probably
- 15:03like everything
- 15:04let's let's remove everything
- 15:07and have a look how this will look like
- 15:09I'm gonna also wrap everything in its
- 15:13own form because finally that is
- 15:15something that needs to be submitted
- 15:18all right
- 15:21okay that's great however the submit
- 15:24needs to be on a full width so w full
- 15:28block is something I'm going to remove
- 15:29we have submit and cancel
- 15:31which is perfect
- 15:35however even submittent cancel is not
- 15:38necessary to be displayed until you
- 15:40click inside leave a comment right so we
- 15:45can add an event for that using
- 15:48alpine.js to show submit and cancel
- 15:51buttons whenever user clicks inside to
- 15:54leave a comment so the submit and cancel
- 15:57we can put in its own div
- 16:01and then we give it a class
- 16:06well let's give it class hide I think
- 16:08let's see it or hidden
- 16:13okay they are hidden perfect and when I
- 16:17click inside then this should be visible
- 16:19so I'm gonna
- 16:20use alpine.js
- 16:23to run X init
- 16:26and here we have this object
- 16:28if I remember correctly I have actually
- 16:31of like four hours course uh full course
- 16:34about alpine.js but I don't actually use
- 16:37it very often that's why I I might not
- 16:39remember everything but in excellent we
- 16:42can specify what's going to be the state
- 16:45for this div element like
- 16:49um
- 16:50focused for example
- 16:52August equals false
- 16:56and then we can add this class based on
- 16:59the condition like class
- 17:03equals if log used then we provide here
- 17:08nothing if not focused then we provide
- 17:12it here
- 17:13hidden
- 17:17okay let's check this
- 17:24so we save this if it's not focused
- 17:29Focus false
- 17:32if it's focused yeah which this should
- 17:35not be visible
- 17:38I think in surfix in it there should be
- 17:41state
- 17:42focused false let's leave it like this
- 17:44and at the moment yeah we don't see the
- 17:48buttons If I set this focused true
- 17:52then we see those buttons perfect so we
- 17:54set this into focused false uh well that
- 17:59is the container for the input field I'm
- 18:00going to give it margin button 2.
- 18:03perfect
- 18:05and whenever we click inside so let's
- 18:08use
- 18:10uh click
- 18:14I'm going to set focused
- 18:18um
- 18:19pocket equals true however we need to
- 18:22handle
- 18:23polar case as well so
- 18:26we clicked
- 18:28buttons appear but then when you
- 18:32yeah that's that's actually fine so we
- 18:34we're about to start writing a comment
- 18:36but whenever we click cancel that should
- 18:39be changed so on cancel
- 18:42click we said focused equals false
- 18:49okay
- 18:51that's perfect
- 18:53that's perfect
- 18:55now this I'll leave a comment can even
- 18:57be changed into
- 18:59text area
- 19:01let's see
- 19:07let's remove this ID and name and type
- 19:11text and maybe autocomplete as well so
- 19:13everything except classes we have
- 19:16placeholder scroll down below
- 19:19hold on
- 19:20I did something wrong
- 19:22text area
- 19:27here we go
- 19:29so here we have this leave a comment and
- 19:32I'm going to specify here Colin rows
- 19:35equals one row
- 19:38if this is focused
- 19:42then we provide
- 19:44uh
- 19:46maybe like a six rows otherwise we
- 19:49provide just one
- 19:53okay when I click inside then this
- 19:55increases
- 19:57that's perfect
- 20:00okay six is maybe too much
- 20:03probably four
- 20:06now let's actually try to save comments
- 20:09in the database we type something lorem
- 20:11ipsum
- 20:13and when I hit submit we're going to
- 20:15actually submit the form
- 20:17on the form I'm going to add method to
- 20:21be post
- 20:23and it will also add action
- 20:25to be
- 20:28well
- 20:29do we need this action
- 20:32we might not need I'm going to use wire
- 20:36a clique and whenever this happens let's
- 20:40call the method create comment
- 20:46okay
- 20:49in the actual
- 20:51comment create component class I'm going
- 20:54to create I'm going to Define public
- 20:58ring
- 21:00comment as a text
- 21:02so and I'm going to use that comment
- 21:05as a two-way data binding on this text
- 21:09area so I'm going to use wire
- 21:11modal to be comment and we can also try
- 21:16to Output what is the comment here
- 21:21and whenever we can even remove this
- 21:24method post I believe or we can we can
- 21:27leave this uh let's see what's the
- 21:29actual comment
- 21:31here so
- 21:33let's click on this unable to call
- 21:35component method create comment not
- 21:37found that's fine let's open
- 21:40let's open command create and create
- 21:43that function
- 21:45create comment at the moment
- 21:48I'm just gonna dump into tie just maybe
- 21:52one okay I don't want to do anything at
- 21:55the moment let's just have a look
- 21:58reload the page here we have that I
- 22:00click inside
- 22:01and it actually calls this
- 22:05comment create
- 22:07why does
- 22:09why does it call it well
- 22:12um
- 22:14not to over complicate things
- 22:17I'm going to give it a click wire
- 22:19click equals create
- 22:24comment
- 22:27let's remove this type Summit even or
- 22:29maybe change it into type pattern or I'm
- 22:32going to completely even change these
- 22:35form into div that's we're using Live
- 22:38Wire we are not actually like um
- 22:41submitting the form in a traditional
- 22:43understanding so I'm going to remove the
- 22:46method and wire click from here so I
- 22:48save that
- 22:49and now let's have a look so test
- 22:54comment and as we type we see that the
- 22:56comment is actually updated using 280
- 22:59binding I click on submit and now I see
- 23:01this one that's perfect so the comment
- 23:03was actually actually created
- 23:06now we need to save that comment so
- 23:09let's use comment model create
- 23:12and provide comment
- 23:17that's going to be this comment we will
- 23:21need host underscore ID
- 23:25and we don't have access to post I think
- 23:28if we check viewblade we pass post to
- 23:31comments that comments is the component
- 23:35right here we actually have access to
- 23:38these comments do we have so let's check
- 23:41these comments
- 23:43component Livewire class
- 23:46and
- 23:47yeah we don't have this host here
- 23:51declared which can be available in the
- 23:54comments
- 23:56let me check up for downward so we
- 23:59Define public posts we need to do the
- 24:01same thing and then unmount we need to
- 24:03assign this to post so I'm going to do
- 24:05the same thing
- 24:08now this post is available in the
- 24:11comments plate and I can take these and
- 24:14pass it down to comment create
- 24:17like this I need to open comment create
- 24:21and do something similar
- 24:27okay in this post needs to be defined
- 24:30and now we have this post available here
- 24:33so I can use this
- 24:36post
- 24:37ID
- 24:39and then obviously we need user ID
- 24:43if the user is trying to create post but
- 24:47user doesn't exist we need to redirect
- 24:49to to the login page so I'm going to try
- 24:52to get out
- 24:56user
- 24:57and check if the user does not exist we
- 25:02return redirect
- 25:07redirect
- 25:09can we call this redirect okay
- 25:12roads or we can specify it
- 25:16log in here
- 25:17Maybe
- 25:20we need the URL so we can specify
- 25:21logging here so let's save this however
- 25:25if that exists we are gonna execute user
- 25:28ID
- 25:30now I'm going to open the browser
- 25:33we have some kind of syntax errors
- 25:37somewhere
- 25:41I don't see that let's reload the page
- 25:44okay that was fixed and at the moment
- 25:47I'm authorized however if I log out
- 25:50and then open
- 25:52one of the posts scroll down below type
- 25:55comment and then type submit I'm
- 25:59redirected to the login page and this is
- 26:01exactly what I wanted now I'm going to
- 26:03try to log in
- 26:04I'm going to click on the articles
- 26:08and let's also
- 26:12let's also have a look if the comment is
- 26:14created so comment equals comment create
- 26:17but let's dump and die
- 26:21this comment and have a look
- 26:24I'm going to close this
- 26:27test comment click on submit
- 26:32and I guess the comment is created so
- 26:34let's check the database
- 26:37we see comments table inside there
- 26:39there's one comment with the text
- 26:41comment awesome so we have just created
- 26:43comment now we need to update the view
- 26:48and start iterating and rendering
- 26:50comments so I'm going to click this
- 26:52submit comment a few times to create
- 26:54multiple comments with um
- 26:57with at the moment with the same text
- 26:59but that's fine
- 27:02okay now let's go and comment create
- 27:06I'm going to actually remove
- 27:10this comment
- 27:12I don't need that
- 27:14and let's go now in the comments
- 27:18actually let's go in the comments
- 27:20component
- 27:22and right here we are going to select
- 27:26all the comments active comments in pass
- 27:29it down to the comments and right here
- 27:31we need to iterate and then render each
- 27:34individual comment
- 27:35so we can do this in the render so
- 27:38comments equals comment
- 27:42where
- 27:45host ID
- 27:47equals to this post ID
- 27:53and we need to call get well probably we
- 27:57even need to call
- 28:00paginate because if there are too many
- 28:02comments
- 28:04not all of them should be displayed
- 28:08like okay let's start step by step I'm
- 28:11going to call get and I'm going to query
- 28:12all of them so we have all the comments
- 28:15and I'm going to pass it to
- 28:18comments
- 28:20blade file so right here I have comments
- 28:23now let's start iterating our comments
- 28:27is comment
- 28:30and then I'm going to use a live wire
- 28:33comment item component and pass it
- 28:38comment to be base comment
- 28:41now we need to open
- 28:43comment item component
- 28:46and we need mount
- 28:50here public function
- 28:53oblique function Mount and we are going
- 28:56to accept
- 28:58uh comment here
- 29:02let's save this in
- 29:04public
- 29:06comment
- 29:10like this
- 29:12comment equals even comment
- 29:16now this comment is already available in
- 29:18the comment item so now let's open
- 29:21comment item
- 29:23and here let's just output comment which
- 29:27is a model
- 29:29and second comment which is an actual
- 29:31column name
- 29:33so I save this now reload the page
- 29:35scroll down below and we see comment one
- 29:38comment two common three and so on so we
- 29:41have all the comments available
- 29:43so now I need some kind of inspiration
- 29:45what information I can display for each
- 29:49comment so comments section and let's go
- 29:53in the images
- 29:55okay let's click one of those like we
- 29:58need username user Avatar username the
- 30:02time when that happened
- 30:06we don't have upvote downward at the
- 30:08moment so we can skip that we have reply
- 30:12so I think that's it
- 30:13that's all what we can do and all all
- 30:16the templates will give us roughly the
- 30:19same type of structure
- 30:22so let's create one div
- 30:25uh which will have display of flex
- 30:29inside there 1D which will be for the
- 30:32authorized user Avatar something like
- 30:35this
- 30:36we don't actually have Avatar management
- 30:39but yeah we can leave this as it is
- 30:41right now so it's going to be a dam
- 30:43image whatever
- 30:45and the second will be an actual
- 30:49um comment text
- 30:52okay
- 30:54so this is Avatar then we have div
- 30:58inside the div the first
- 31:02div will be
- 31:05the username
- 31:07the comment user name author of this
- 31:11comment basically like John Smith let's
- 31:15type like this
- 31:17and inside there we're going to also
- 31:19have so we can make this like a link
- 31:22with a hashtag at the moment we don't
- 31:25have the user's own page so we can just
- 31:28type John Smith there and then we also
- 31:31need the time when the comment was
- 31:34actually made so let's use comment
- 31:38comment uh created it
- 31:42let's output like this and we can change
- 31:44this into
- 31:46relative format maybe later
- 31:51then down below we have
- 31:53div which contains the whole comment
- 31:57actual content
- 31:59like this
- 32:01okay and down below we can have reply
- 32:05button
- 32:07here let's create another div
- 32:10let's create a with href and reply
- 32:19okay
- 32:22that's good let's save this and have a
- 32:24look so I have John Smith
- 32:27uh the reply is
- 32:31in a wrong place
- 32:34this one has display Flex
- 32:39I see
- 32:41and this reply should be right here
- 32:46okay John Smith so this needs to have a
- 32:50different styles like text blue
- 32:54or what color do we use
- 32:57like in our comment create component we
- 33:01use
- 33:04Indigo 600 so we can use the same style
- 33:08in the comment item
- 33:12indigo 600.
- 33:15not ring but text indigo 600.
- 33:19okay we can even make font semi Bolt
- 33:28okay good we don't have Avatar at the
- 33:31moment which is which is okay we can
- 33:33leave this
- 33:35then we specify
- 33:38here as well replying is to have text
- 33:41Indigo 600
- 33:45we obviously need margin bottom three
- 33:50maybe even
- 33:52or
- 33:54as for the avatar
- 33:57we can grab the hero icon
- 34:01user at the moment
- 34:06get it
- 34:07and I'm going to put this here
- 34:10this is our icon
- 34:13and this div will have with a W 16 8
- 34:2116.
- 34:24let's give it also legs
- 34:27items Center
- 34:29justify Center and BG Gray 100.
- 34:36that's probably too much maybe reduce it
- 34:38into 12.
- 34:43PG grade 200 and give it rounded
- 34:46a rounded full
- 34:51okay and let's give this one get three
- 34:56okay here we have at the moment this is
- 34:58dummy Avatar but uh later of course this
- 35:01can be implemented we have space for
- 35:03that
- 35:04this reply let's give it text
- 35:08small
- 35:12perfect and this comment let's give it
- 35:16text Gray 700
- 35:22so it's a great comment I'm going to
- 35:24remove this and type lorem lorem ipsum
- 35:27to see just how big text look like and
- 35:30this is good
- 35:32this is good
- 35:35okay perfect let's return
- 35:40comment and obviously if the comment is
- 35:43made by Me by the user who is actually
- 35:46looking at this we need a delete and
- 35:49edit buttons as well so right here
- 35:53I can
- 35:55put two
- 35:57two more elements
- 36:00this will be delete
- 36:03this will be edit
- 36:06for edit excuse me
- 36:10edit for edit we can use like blue color
- 36:14for delete we can use red color
- 36:19okay good let's put
- 36:21uh let's put asterisk maybe here or some
- 36:25Dot
- 36:27oh no it's not good idea
- 36:34or we can just put two extra margins
- 36:38like margin left or margin right three
- 36:43okay all of them is created by me so
- 36:46that's why I I should see them but if
- 36:49the user is not me so basically let's
- 36:52use if
- 36:54comment
- 36:56user
- 36:59comment user ID if that is not the same
- 37:03as the authorized user ID like
- 37:06um
- 37:08I'm going to use auth facade ID
- 37:14if the ID is not the same
- 37:18now if it is the same as comment user ID
- 37:21then we display edit and delete
- 37:25and if let's format the code and now
- 37:29let's have a look so I see everything if
- 37:31I copy this and open in incognito mode
- 37:35I don't see edit and delete which is
- 37:39good now I want to display them
- 37:43these dates in a human readable format
- 37:46so I think carbon supports that so if I
- 37:50use carbon
- 37:55um
- 37:56well the comment created is actually
- 37:58already an instance of carbon isn't it
- 38:01so if I just call method
- 38:04here
- 38:05diff
- 38:08or humans I think this is the method
- 38:11name so if I call this
- 38:13and have a look here I see these 12
- 38:16minutes ago fantastic
- 38:20okay so I have that I think I should put
- 38:24this in a span and give it like gray
- 38:27color
- 38:28text Gray 500 maybe
- 38:35okay
- 38:37it's perfect that's perfect
- 38:40okay now the thing is that when I leave
- 38:42a comment test comment
- 38:47when I click submit
- 38:49uh I should be able to see this comments
- 38:52immediately
- 38:54uh probably at the top and even this
- 38:57section should be probably at the very
- 38:59top so
- 39:01let's take care of this
- 39:04in the comment section first I'm going
- 39:06to have the leave a comments box and
- 39:10then other comments so that this will be
- 39:13at the very top
- 39:14these create comment
- 39:18let's give this one
- 39:20margin button or something like this
- 39:25we have a extra white space
- 39:28and the thing is that whenever the
- 39:30comment is created we need to tell the
- 39:32parents to re-render its children
- 39:36so if I just reload the page
- 39:39these common test comment is at the very
- 39:41bottom also
- 39:43the comments needs to be sorted by
- 39:45descending so when I select comments
- 39:47right here we can specify order by disk
- 39:54created it
- 39:56save reload the page and we see my
- 39:59latest comment is at the very top again
- 40:01let's type a new comment here and click
- 40:06submit
- 40:07and if I reload the page I see new
- 40:09comment right here so I'm going to open
- 40:11this comment create and whenever the
- 40:13comment is created instead of damping I
- 40:16want to call I want to emit
- 40:19now aim it up tell the parent that
- 40:22comment created
- 40:26so this is the event and I can also pass
- 40:29a comment that was created
- 40:33not this comment but the actual comment
- 40:36that was created
- 40:38now I'm going to open comments class
- 40:41right here and I will need event
- 40:45listeners here
- 40:48I believe it's called event list let's
- 40:51create public array event listeners
- 41:01and right here I'm going to define the
- 41:04event name comment created and the
- 41:07actual function in this case let's call
- 41:11the function the same name comment
- 41:13created
- 41:14this should be probably listeners yeah
- 41:17and we can remove this and we can make
- 41:19this protected it should be protect it
- 41:21by default
- 41:22okay so we have render Mount and at the
- 41:25very bottom I'm going to add this
- 41:28function public function comment created
- 41:31and we're going to accept the comment
- 41:34right here
- 41:35and let me actually now die dump and die
- 41:39from here just one two three okay so if
- 41:41the code comes right here this means
- 41:43that our event Works successfully
- 41:47so I save this and let's have a look
- 41:52test comment
- 41:54click on submit okay we see one two
- 41:56three so our comments actually works and
- 41:59now this render how this render how we
- 42:04tell how we should tell the a lot of
- 42:06Live Wire to call this render method
- 42:09let's usually remove this because it
- 42:11might even do this automatically
- 42:14like a new comment one let's click
- 42:19submit
- 42:21and something happened
- 42:25okay let's leave new comment too
- 42:29okay nothing happened so what we can do
- 42:32is
- 42:35create here
- 42:37public
- 42:39comments which can be an array
- 42:42of comments like this
- 42:45so now in Mount we can select these
- 42:48comments
- 42:50these comments equals
- 42:53this
- 42:55okay so we select the comments and we
- 42:58don't need to pass those comments from
- 43:00here because they are public properties
- 43:02they will be available in the blade
- 43:04however whenever comment is created what
- 43:08we can do is get this comment which by
- 43:11the way should be an instance of comment
- 43:12and this
- 43:15comments equals we need to put this new
- 43:20comment
- 43:22right here
- 43:23and then we can of course
- 43:26provide other comments as well
- 43:31like this I'm sure like I hope this will
- 43:35work so let's see
- 43:37uh okay so this is a collection
- 43:42okay we can first remove this
- 43:46or maybe we can provide this collection
- 43:48so this is eloquent collection so we can
- 43:51provide comments needs to be a
- 43:55collection
- 43:57um
- 43:58database eloquent collection
- 44:01like this and now because this is a
- 44:04collection maybe this has like a merge
- 44:07or something like this or I can even use
- 44:10array merge
- 44:14or array concut
- 44:18let's use or emerge
- 44:21I'm going to provide my comment new
- 44:24comment and this
- 44:26comments
- 44:30I save that
- 44:32and let's see
- 44:35okay so we scroll down below new coming
- 44:38to now let's create new comment three
- 44:41click on submit
- 44:44array to string conversion
- 44:48where did that happen
- 44:53array to string conversion and we don't
- 44:56have
- 44:58to have the exact file
- 45:00where this happened
- 45:08I don't find that
- 45:12and probably
- 45:15something is wrong here so if we just
- 45:19run execute the same query when the
- 45:22comment is added
- 45:25like this
- 45:26and by the way
- 45:28um this 4 is too much maybe two will be
- 45:31good
- 45:33okay
- 45:34new comment
- 45:37or and click submit
- 45:40okay area to string conversion
- 45:43where does this happen
- 45:45let's check the comments component
- 45:55okay in this case we don't do anything
- 46:01if we comment this line
- 46:06new comment five
- 46:10okay we still get this
- 46:16not sure where it comes from
- 46:23so I think the actual problem is coming
- 46:25from the comment Creator we're passing
- 46:27here modal so if we just change this and
- 46:32pass comment ID instead of the model and
- 46:35if you go in the comment section and I'm
- 46:37going to accept integer right here ID
- 46:40then I can select the comment based on
- 46:43the ID but in this case I'm going to
- 46:45just select everything and have a look
- 46:47if that works a new comment
- 46:51uh six and click submit
- 46:54okay something happened
- 46:58okay we see new common six right here
- 47:00new comment
- 47:02seven
- 47:07okay where's new common seven
- 47:11it's slightly changes the ordering I
- 47:16think
- 47:20paste comments
- 47:26this appears at the top of this
- 47:34which looks like to be the first one
- 47:38okay if I try to get the comment
- 47:43comment where
- 47:49ID equals
- 47:51this one
- 47:53and get simply first
- 47:57then I can call array merge
- 48:01past the comment and this
- 48:06comments
- 48:09and we are going to have a look
- 48:11new comment eight click on submit
- 48:18okay
- 48:19here we need to put this in the
- 48:23array square brackets
- 48:26new comment nine click on submit
- 48:34okay I want to merge collection
- 48:39I'm going to look for these laravel
- 48:41merge collections
- 48:46sure there will be
- 48:48something let's search for merge
- 48:51you see that
- 48:53I can create
- 48:55or um I won't concat Maybe
- 48:58yes I won't concat so I'm going to
- 49:01create a collection and then concat with
- 49:03the previous one so here I have comment
- 49:06I'm going to call collect
- 49:10on
- 49:11comment
- 49:13and then
- 49:15on this
- 49:16call concat with these comments
- 49:24okay let's have a look
- 49:27new comment pane
- 49:30click on submit
- 49:33okay
- 49:34um can't assign collection to property
- 49:36comments of type
- 49:42well let's remove this type
- 49:47new comment 11.
- 49:52well it works but I don't know why why
- 49:5611 record
- 50:00is not anywhere here
- 50:06we need to check
- 50:09how many
- 50:11records are there in the comments so in
- 50:14the database at the moment we have 20
- 50:16comments
- 50:17if I just add like 12 click submit
- 50:22we see 21.
- 50:25the first one
- 50:28I should have attributes the first one
- 50:31is actually 12.
- 50:41okay that's probably related to some
- 50:44kind of indexing caching issues so
- 50:48basically the collection is successfully
- 50:50updated but on the front end it is not
- 50:53updated successfully
- 50:56so if I just try this once again
- 51:00okay
- 51:01there must be a solution for that now
- 51:04live wire
- 51:06Live Wire
- 51:08um
- 51:08Loop index something like this
- 51:13um
- 51:14Loop
- 51:16index Loop
- 51:21key something like this like there's
- 51:24these problems in alpine.js if you don't
- 51:28provide eight wire key to elements
- 51:30inside Loops wire key it must be it a
- 51:34search for wire key
- 51:37here it goes so if we open this
- 51:43comment item
- 51:45and add wire
- 51:48e here and it's going to be
- 51:53comment
- 51:55ID
- 51:56we can even prefix like comments Dash
- 51:59comment ID now we need to have a look
- 52:02I'm adding 14
- 52:06still not working
- 52:11okay let's search for
- 52:14maybe we need to do this note here
- 52:18but in the comments
- 52:23maybe here
- 52:25wire key equals let's paste it
- 52:32comment ID is this correct syntax
- 52:37yeah I think so
- 52:40okay let's check this one last time
- 52:42hopefully it's gonna work and it worked
- 52:45yeah that was the problem so now I can
- 52:48add 16
- 52:49it's
- 52:51attempt to read property ID on array
- 52:58okay what was that okay
- 53:03comment ozere
- 53:08okay that's range
- 53:11why was that array I'll just double
- 53:13check this 17 submit that worked
- 53:18I try now 18
- 53:21submit and we got this error
- 53:24okay so let's actually print
- 53:27what is
- 53:30comment and I'm going to comment this
- 53:31line
- 53:34here we see
- 53:3618. now let's print
- 53:3919. it's there now let's print 20
- 53:46something is wrong
- 53:48I don't see 20 here
- 53:56give me to one type of string array
- 53:59given
- 54:00so I think the problem is right here
- 54:03when we convert these array of comments
- 54:07into a collection and then concatenate
- 54:09this with these comments so if we just
- 54:12change this into probably a prepaid
- 54:16method like we have these comments which
- 54:21on which I'm going to call prepend pass
- 54:25selected comment
- 54:27and have a look
- 54:29so I'm going to provide 30 here
- 54:32that was added 31
- 54:34that was added 32 and so on so that
- 54:38works it successfully Works
- 54:41um which is which is excellent now
- 54:43whenever the comment is added I want to
- 54:46remove the focus as well as the clear
- 54:48the model so that should be slightly
- 54:51easier in the comment create I want to
- 54:58uh whenever we emit after VM it's let's
- 55:00set this comment equals an empty string
- 55:05and that will make this text area empty
- 55:09however we're going to also set the
- 55:12focus to be false
- 55:16now we need to listen to that comment
- 55:18created event on the component and
- 55:21basically set the focus to be false so I
- 55:24think we can do this using uh by
- 55:27listening to that comment created event
- 55:30right here so I'm going to use comment
- 55:34or how should we do this like geeks on
- 55:37comment created
- 55:40I'm not sure if this is going to work
- 55:42but we're going to double check and then
- 55:45when this happens I'm going to set
- 55:46focused
- 55:48equals false
- 55:52so we save that
- 55:54and have a look
- 55:56test one
- 55:59okay the model it didn't work the model
- 56:02got empty
- 56:03but the focused one said maybe we need
- 56:07to listen on a window
- 56:11comment create is the name proper name
- 56:15here we have this comment created now
- 56:18let's check this once again
- 56:20test two click on submit
- 56:24that doesn't work
- 56:32well I guess I can use wire
- 56:35keyword here like I'm going to Define
- 56:38init which will be called whenever the
- 56:41component is initialized and we can type
- 56:43constant log
- 56:45init called
- 56:48let's let's check this let's open the
- 56:51browser I'm going to move this on the
- 56:53right side
- 56:55and we're seeing it called
- 56:57and we can also access wire keyword
- 57:03wire and then listen on the event like
- 57:07comment created and whenever this
- 57:10happens
- 57:12we can call our callback function and
- 57:14set this
- 57:16focused equals false I guess
- 57:21let's have a look
- 57:23we don't see any error which is good
- 57:27let's actually type console.log whenever
- 57:30comment is created
- 57:36and let's leave test three submit okay
- 57:40here we go that worked so comment
- 57:43created the cancel Summit buttons were
- 57:45disappeared we see test three now let's
- 57:48add test 4.
- 57:51okay perfect
- 57:53now let's open comment item and we are
- 57:56always outputting John Smith right here
- 57:58we need to access to the user right
- 58:02that's going to be comment the comment
- 58:05doesn't have relationship to the user so
- 58:07we're going to open comment.php and
- 58:10we're going to add
- 58:12public function user here return this
- 58:17belongs to
- 58:22user
- 58:24class and let's define the return type
- 58:31I'm going to move this up right here so
- 58:33now comment has access to user so
- 58:36comment user
- 58:39name let's see what this will print we
- 58:42see admin so basically every comment is
- 58:45at the moment made by admin
- 58:48okay so that's good so far so good at
- 58:51the moment we print all the comments we
- 58:52can add pagination or load more later
- 58:55but we can leave this right now
- 58:57we're going to implement delete and edit
- 59:00as well let's test this once again like
- 59:02test five click on submit and that was
- 59:05created perfect so we need to implement
- 59:07now delete edit and reply on those
- 59:10comments let's start with very simple
- 59:12delete
- 59:13here we have this delete button I'm
- 59:15going to add wire click
- 59:20delete
- 59:22delete comment
- 59:25now let's open comment item component
- 59:30and let's create public function delete
- 59:33comment
- 59:34and here we have access to the comment
- 59:38so we just need to execute these comment
- 59:44equals not equals simply we're going to
- 59:47call delete
- 59:49but we need to also Aim It event to the
- 59:52parent that comment was deleted in list
- 59:55needs to be updated it needs to be
- 59:57removed from the list
- 1:00:00so let's call this
- 1:00:04emit app
- 1:00:06comment deleted
- 1:00:08and we're going to pass this
- 1:00:11comment
- 1:00:13ID
- 1:00:15well let's take the ID
- 1:00:19equals this comment ID before I delete
- 1:00:23and then I pass it
- 1:00:28now let's open comments component
- 1:00:34comments component
- 1:00:37and here just like I have the comment
- 1:00:40created I'm going to duplicate this
- 1:00:41comment deleted
- 1:00:43let's create this function comment
- 1:00:46deleted we accept
- 1:00:49ID here and we need to remove that
- 1:00:52comment with this ID from the collection
- 1:00:56of comments
- 1:00:59okay let's have a look at the collection
- 1:01:02methods like is there any remove
- 1:01:07okay this removes an item from The
- 1:01:10Collection by its key
- 1:01:13okay can we call something like this
- 1:01:17comments
- 1:01:20pool and provide ID
- 1:01:23now we cannot do this because key is an
- 1:01:26index not ID
- 1:01:28okay reject
- 1:01:32filters collection
- 1:01:35using the given closure the closure
- 1:01:37should return true if the item should be
- 1:01:39removed from the resulting collection so
- 1:01:42we can use reject in this case
- 1:01:47this
- 1:01:49comments reject we get right here the
- 1:01:53actual comment
- 1:01:55it should not be an INT it's a comment
- 1:01:57and we are checking if the comment
- 1:02:01if the comment ID is the same
- 1:02:06as the given ID which we are going to
- 1:02:10use here
- 1:02:12so then we are rejecting that comment so
- 1:02:15finally we're going to have filtered
- 1:02:17comments and this comments which has the
- 1:02:20same ID will be removed from this
- 1:02:22comments
- 1:02:24comments collection so let's remove this
- 1:02:26key and let's test this I'm going to
- 1:02:30delete these tests four click right here
- 1:02:32okay we need to prevent
- 1:02:35uh when to prevent
- 1:02:39default
- 1:02:41click prevent
- 1:02:44that should work
- 1:02:48that was deleted by the way so let's
- 1:02:50click delete on test three that was
- 1:02:54deleted Test 2 date was deleted okay so
- 1:02:58just like this we are deleting if you
- 1:03:00want of course you can add additional
- 1:03:03like live wire
- 1:03:05or JavaScript alert right here are you
- 1:03:08sure you want to delete that and if the
- 1:03:10user proceeds then we can you can
- 1:03:13actually proceed and delete that
- 1:03:16okay so I'm Gonna Leave This as it is
- 1:03:18now and let's click on let's Implement
- 1:03:21editing of the comments so whenever we
- 1:03:25click edit we want in the same place
- 1:03:28probably right here the
- 1:03:32inputs to be displayed so that user can
- 1:03:34edit that and then submit and cancel
- 1:03:36buttons will be right there as well
- 1:03:40now let's start working on two edit
- 1:03:43comments whenever we click edit button
- 1:03:45it really jumps at the top because we
- 1:03:47have hashtag right there deleting
- 1:03:50is already implemented so let's open
- 1:03:53post item blade and let's have a look so
- 1:03:58this is post uh sorry we want comment
- 1:04:02item
- 1:04:04and at the very bottom we have this edit
- 1:04:06button so just like we are listening to
- 1:04:10the click of the delete button using
- 1:04:12Live Wire I'm going to listen to click
- 1:04:16and call prevent as well right here and
- 1:04:19I'm going to call method start comment
- 1:04:22edit
- 1:04:24now let's open comment item class and at
- 1:04:29the very top I'm going to define a
- 1:04:30Boolean property
- 1:04:32editing which by default will be false
- 1:04:37okay and down below let's define the
- 1:04:40function start a comment edit whenever
- 1:04:43this method is called editing will
- 1:04:45become true
- 1:04:47right so in the comment item now we have
- 1:04:50this editing flag available and this is
- 1:04:53where actual text is outputted common
- 1:04:56text but if we are in editing mode we
- 1:04:59need to do it slightly differently like
- 1:05:02if
- 1:05:04if editing
- 1:05:08then we need to do something else
- 1:05:10in else case we render the comment again
- 1:05:13and then we have end if
- 1:05:17okay what do we need to do here so we
- 1:05:19need to
- 1:05:21we need to render the similar inputs
- 1:05:24like we have here we can create new
- 1:05:27input but I'm going to try to reuse an
- 1:05:30existing comment create component if we
- 1:05:33open now comment create which is uh
- 1:05:36created at the moment for just creating
- 1:05:40a comment
- 1:05:41when to we can customize this a little
- 1:05:44bit I'm going to also open comment
- 1:05:48create class here all right now in
- 1:05:51comment item I will try to use that
- 1:05:54component Live Wire
- 1:05:56comment slash create okay if we are in
- 1:06:01editing mode we need to render this
- 1:06:03input
- 1:06:04okay now when I click edit we see this
- 1:06:07input field we are in editing mode but
- 1:06:10we have some extra work obviously first
- 1:06:12we need to load the actual value which
- 1:06:16is written right here inside this text
- 1:06:18area
- 1:06:21also we want to trigger like a click so
- 1:06:24that submittent cancel buttons are
- 1:06:26immediately visible whenever we click
- 1:06:28this edit so how to do this in this
- 1:06:31comment create we can in the mount we
- 1:06:34can accept one additional argument which
- 1:06:37will be the modal comment model so
- 1:06:40basically if we are editing we can
- 1:06:43accept this model I'm going to call this
- 1:06:46um
- 1:06:47let's call this comment model by default
- 1:06:50it's going to be now so let's the
- 1:06:52comment creation will not be broken and
- 1:06:56then this
- 1:06:58um okay I'm going to Define also modal
- 1:07:01here public
- 1:07:03comment
- 1:07:05comment modal equals null and let's
- 1:07:09specify question mark here as well so we
- 1:07:12Define comment modal equals to received
- 1:07:16comment model and we're going to also
- 1:07:18check if the comment model has comment
- 1:07:22inside there or if it is if it exists so
- 1:07:26let's do like this
- 1:07:27of this comment which is an actual text
- 1:07:30which needs to be displayed in the text
- 1:07:32area this text will equal if the comment
- 1:07:36model exists then it's going to be
- 1:07:38comment model comment
- 1:07:40so if that exists we are editing and we
- 1:07:44are taking from this model the comment
- 1:07:47column data otherwise we take it empty
- 1:07:51so if I say this already and reload the
- 1:07:54page and click on this
- 1:07:57um I expected to see
- 1:08:00the comment or loaded right here I know
- 1:08:03why I don't see because we don't pass a
- 1:08:05comment model so let's specify comment
- 1:08:07model from here and there's going to be
- 1:08:10current model
- 1:08:12so we're going to pass comment as a
- 1:08:14model
- 1:08:15then when we click edit we see 30 loaded
- 1:08:19inside okay now whenever we click edit
- 1:08:22we won't immediately submit and cancel
- 1:08:24buttons to be visible okay how we are
- 1:08:28going to do that in the comment create
- 1:08:30we display those buttons If focused is
- 1:08:34set to true so we probably need to
- 1:08:38define a new variable like is edit
- 1:08:42variable so if we are editing we want
- 1:08:45those buttons to be always visible so if
- 1:08:48we are in edit mode
- 1:08:50the inside this comment create now we
- 1:08:53have access to this comment model
- 1:08:55okay and we it might be null or it might
- 1:08:58be object so we need to check if comment
- 1:09:01model exists we are going to Output true
- 1:09:04in the JavaScript otherwise we're going
- 1:09:07to Output false so pay attention
- 1:09:10that I'm using right here true or false
- 1:09:12as a string because this portion needs
- 1:09:17to be replaced whatever we are
- 1:09:18outputting true or false and if it needs
- 1:09:21to be true simply this will be replaced
- 1:09:23with true and this is exactly what I
- 1:09:25want
- 1:09:27so now whenever this is edit we if it's
- 1:09:32either focused or edit let's do like
- 1:09:34this if is edit or Focus then we display
- 1:09:39it if it's edit or focused then the
- 1:09:43number of rows will be two okay we do
- 1:09:46like this now let's reload the page and
- 1:09:49click edit and now we immediately see
- 1:09:51buttons as well as this 30 number Okay
- 1:09:56small thing on the submit I'm going to
- 1:09:58give it margin write 3
- 1:10:02to have a small margin between this
- 1:10:04cancel and submit and also I want cursor
- 1:10:08to be inside the text area whenever I
- 1:10:11click edit
- 1:10:12so I'm going to listen inside the init
- 1:10:15basically this is triggered every time
- 1:10:18the component is created I'm going to
- 1:10:20check if this
- 1:10:22is edit
- 1:10:24then I'm going to call a focus method on
- 1:10:27the text area but I'm going to specify
- 1:10:30xref on the text area this is alpine.js
- 1:10:33to basically Define a name for that
- 1:10:38text area component let's give it input
- 1:10:41and then these refs input Focus
- 1:10:46will do the rest
- 1:10:48so now click edit and we're focused
- 1:10:52inside the text area and we can start
- 1:10:53editing now whenever we click cancel we
- 1:10:57need to hide everything so let's have a
- 1:11:00look in the cancel button here we have
- 1:11:02that so now whenever we click cancel
- 1:11:05nothing happens let's check also
- 1:11:08developer tools if we have some errors
- 1:11:10we know it's about it immediately
- 1:11:13focused equals four so we need to set is
- 1:11:16edit
- 1:11:19to be false as well
- 1:11:22whenever we click cancel
- 1:11:24okay now edit and cancel
- 1:11:28and buttons disappear but we still see
- 1:11:30these input and that happens because
- 1:11:33comment item is still in editing mode
- 1:11:38right so whenever we click this cancel
- 1:11:42button
- 1:11:44we need to also aim it events to the
- 1:11:46parent so I'm going to call wire
- 1:11:50aim it up and let's call this event
- 1:11:53cancel editing so I'm telling the parent
- 1:11:57component that hey I'm just canceling
- 1:11:59the editing this happens from the
- 1:12:01comment create component which is used
- 1:12:04right here so this component will
- 1:12:05trigger cancel editing and now inside
- 1:12:09that component comment item component we
- 1:12:12can listen to that event let's define
- 1:12:15listeners right here
- 1:12:17on cancel editing we can call a function
- 1:12:19called cancel editing and at the very
- 1:12:22bottom
- 1:12:23we Define this cancel editing this
- 1:12:27editing equals false
- 1:12:30now let's have a look I click edit we
- 1:12:34are in the editing mode I type some
- 1:12:36characters then I click cancel
- 1:12:39and let's have a look
- 1:12:42or I didn't expect
- 1:12:44this still to be visible let's reload
- 1:12:47the page
- 1:12:48type something click cancel and this is
- 1:12:51exactly yeah so I just needed to reload
- 1:12:53the page so click edit type something
- 1:12:56click cancel and it goes back to its
- 1:12:59original value
- 1:13:01that's perfect but now let's handle
- 1:13:03update whenever we click on submit
- 1:13:06button what needs to be done that
- 1:13:08happens in in the comment create
- 1:13:10so now
- 1:13:12the comment create comment will be
- 1:13:14called and simply we need to check
- 1:13:18if this comment model exists it means
- 1:13:21that we are in edit mode
- 1:13:24else
- 1:13:25we are in create mode so the code what
- 1:13:28we have here so far will go in else but
- 1:13:32in in if we need to do the following so
- 1:13:36this comment model
- 1:13:39comment will be this comment and this
- 1:13:44comment will be text area text then on
- 1:13:47this
- 1:13:48comment model I'm going to call Save
- 1:13:51which will save changes in the database
- 1:13:53I'm going to also set this
- 1:13:57this
- 1:13:58comment to be an empty string
- 1:14:01and I will also tell the parent that
- 1:14:04editing is basically finished or like we
- 1:14:07are emitting comment created we need to
- 1:14:10do something similar like comment
- 1:14:11updated so this
- 1:14:14Aim It Up
- 1:14:17comment updated okay I'm not going to
- 1:14:20pass any arguments that's going to be
- 1:14:22enough we are doing this comment updated
- 1:14:24from the comment create which is used
- 1:14:27inside this comment item so in the
- 1:14:30comment item I'm gonna listen to comment
- 1:14:34updated
- 1:14:37and whenever this happens
- 1:14:39I'm going to Define new function
- 1:14:41whenever this happens I'm going to set
- 1:14:44editing to be false like this so I save
- 1:14:49and reload click edit click cancel that
- 1:14:53works magically and now let's give it
- 1:14:55updated so I'm going to click submit and
- 1:14:58that was update now if I reload the page
- 1:15:01it is there it is updated it is perfect
- 1:15:04okay so far so good however one extra
- 1:15:08security step will be right here to
- 1:15:13check if that specific model is owned by
- 1:15:17current user
- 1:15:20I'm going to do this right here if this
- 1:15:23model exists and maybe
- 1:15:28um by the way this if user exists we can
- 1:15:31move this up
- 1:15:33if user doesn't exist we redirect user
- 1:15:36to log in now at this moment we know
- 1:15:38that comment model exists and the user
- 1:15:40exists so we're going to check
- 1:15:42and this
- 1:15:44comment model user ID if that equals or
- 1:15:50let's do like this
- 1:15:52inside the comment model
- 1:15:54I'm going to write additional if
- 1:15:56statement if the comment model user ID
- 1:15:59does not equal it's something different
- 1:16:02from the currently authorized user's ID
- 1:16:06I'm going to throw new like forbidden
- 1:16:09exception or
- 1:16:11um
- 1:16:13I can't throw Source I'm going to Simply
- 1:16:16return Maybe
- 1:16:17a response
- 1:16:21and status code
- 1:16:24403
- 1:16:29I think in the response we can also
- 1:16:31Define I'm going to return
- 1:16:33you are not allowed to perform this
- 1:16:38action
- 1:16:39like this and the status code will be
- 1:16:41403 Forbidden
- 1:16:43so I can test this from the interface
- 1:16:47unless I make a JavaScript Ajax request
- 1:16:51and exactly this is what we are doing
- 1:16:54preventing others from sending
- 1:16:58incorrect inappropriate requests and we
- 1:17:00need to do the same check by the way
- 1:17:02when we are about to delete comment so
- 1:17:07in the comment item
- 1:17:10are right here
- 1:17:12we need to check
- 1:17:15if comment user ID is different from the
- 1:17:20currently authorized user's ID so let's
- 1:17:22get this user from here and by the way
- 1:17:24here we also need to check if the user
- 1:17:26doesn't exist in someone somehow makes a
- 1:17:29delete request
- 1:17:31it should not happen basically so if the
- 1:17:35let's move this down as well
- 1:17:40okay so first we check if the user
- 1:17:43doesn't exist we were direct user to log
- 1:17:44in then if the comment user ID is
- 1:17:46different from the user ID then we
- 1:17:48return the following response on delete
- 1:17:50so extra security step now we have
- 1:17:54deleting of commands which works
- 1:17:56successfully new comment right here
- 1:18:00here we go we can edit this comments
- 1:18:04and it is edit now we need to take care
- 1:18:07of replying comments
- 1:18:10now let's start working on replying on
- 1:18:13comments first of all we're going to
- 1:18:15Define
- 1:18:16pointy parent ID on the comments because
- 1:18:19we haven't defined this
- 1:18:21I'm going to create new migration
- 1:18:25PHP artisan make migration add parent ID
- 1:18:34on comments table
- 1:18:38okay let's open now
- 1:18:40add parent ID
- 1:18:43on comments table
- 1:18:45here we go
- 1:18:47on
- 1:18:54so we need to accept the schema
- 1:18:58like
- 1:19:02like we're doing
- 1:19:05so I'm going to grab this
- 1:19:09let's define own comments table we
- 1:19:13Define
- 1:19:15foreign ID
- 1:19:18parent ID
- 1:19:21and that is nullable
- 1:19:23and that has constrained on comments
- 1:19:28table
- 1:19:29all right and we need to drop that ink
- 1:19:34down as well
- 1:19:36drop column parent ID
- 1:19:39we haven't defined this show so that's
- 1:19:42why we need that and now I'm going to
- 1:19:44open also comment PHP model
- 1:19:47and Define this parent ID right here so
- 1:19:50at the moment we I decided to only allow
- 1:19:53two level of comments so we're gonna
- 1:19:56have like the root level comments in the
- 1:19:59child we are not going to have
- 1:20:00grandchildren of the parent and so on so
- 1:20:03there will be only two level of comments
- 1:20:05and in this case this parent ID will be
- 1:20:07absolutely enough but generally if you
- 1:20:10want to have a very nested
- 1:20:13tree type of data you should probably
- 1:20:16consider something like nested nested
- 1:20:19set model or similar thing okay so in
- 1:20:24this case that's going to be fine
- 1:20:26so we have the parent ideally Supply
- 1:20:28migration PHP Artisan migrate
- 1:20:33here we go
- 1:20:35and now let's open post item
- 1:20:39uh sorry comment item plate and we need
- 1:20:44to listen to this reply wire
- 1:20:49click
- 1:20:51prevent
- 1:20:53start reply
- 1:20:56and that's it start reply now let's open
- 1:20:59comment
- 1:21:01item class as well
- 1:21:03and down below let's create public
- 1:21:05function
- 1:21:07start reply
- 1:21:09okay let's define a flag like similar to
- 1:21:13editing what we have
- 1:21:15public Boolean
- 1:21:18replying
- 1:21:20equals by default this is false
- 1:21:24but whenever we call start replying I'm
- 1:21:28going to set this uh replying equals
- 1:21:32true
- 1:21:34all right now whenever user clicks that
- 1:21:37we need to display
- 1:21:40this type of
- 1:21:41component
- 1:21:43but as a child
- 1:21:46of this component and we also later need
- 1:21:49to handle the case rendering child child
- 1:21:54comments but how do we need to do so I'm
- 1:21:57going to grab these so we are adding
- 1:21:59actually new
- 1:22:01a new comment
- 1:22:03so what I'm going to do down below
- 1:22:06probably here I'm just going to paste
- 1:22:08this and remove these comments this is
- 1:22:10absolutely new comment
- 1:22:12so let's have a look
- 1:22:14let's have a look what happens
- 1:22:16we see this probably not ideal place let
- 1:22:21me have a look so this is the div
- 1:22:24this is the image
- 1:22:26and then this is okay we need to put
- 1:22:28this at the very bottom right here
- 1:22:33save it now let's have a look
- 1:22:37not ideal again and now I'm gonna put
- 1:22:42this
- 1:22:43right here at the very bottom of this
- 1:22:47div
- 1:22:49that should be good
- 1:22:52okay
- 1:22:54so that's actually not bad we always see
- 1:22:57these I'll leave a comments which should
- 1:22:59have a different placeholder which we
- 1:23:01can do no problem
- 1:23:03whenever I click on this it's going to
- 1:23:05expand it whenever I type something it's
- 1:23:07going to save the only thing what we
- 1:23:10should probably do that this input
- 1:23:12should not be rendered unless we click
- 1:23:14this reply
- 1:23:16so what I'm going to do is
- 1:23:19if
- 1:23:21replying is true then we render
- 1:23:27and if then we render this Live Wire
- 1:23:30command create
- 1:23:31now we don't see as soon as I click this
- 1:23:34reply then I see this leave a comment
- 1:23:37and also we should trigger like the
- 1:23:40focus on that as well
- 1:23:44okay let's go in the let's close the
- 1:23:48migration and model
- 1:23:51this one as well and let's open comment
- 1:23:54create
- 1:23:57and also comment slash create blade file
- 1:24:03so the text area and the buttons is only
- 1:24:05visible if it is in edit mode or if
- 1:24:08focused is true
- 1:24:12what if we
- 1:24:13what if we set focused equals true
- 1:24:18based on whether it's a reply or not
- 1:24:23so
- 1:24:24in the comment create
- 1:24:28I'm going to
- 1:24:33I'm going to define a flag let me think
- 1:24:35I'm thinking so I'm going to define a
- 1:24:38flag called
- 1:24:39replying equals false by default
- 1:24:44then I'm going to accept right here
- 1:24:47Boolean variable replying
- 1:24:51which by default equals false
- 1:24:53and I'm going to set
- 1:24:55this replying equals replying
- 1:25:02now let me take this replying and right
- 1:25:06here
- 1:25:07I'm going to Define so if at the moment
- 1:25:11user is replying
- 1:25:14to some comment
- 1:25:15then we set this to be true otherwise we
- 1:25:19set this to false
- 1:25:21so by default it's going to be false
- 1:25:24when I click then this will appear
- 1:25:27however if I click reply we need to pass
- 1:25:31those replying flag
- 1:25:34so from the comment item right here we
- 1:25:37need to pass
- 1:25:39replying equals true so this is actually
- 1:25:42a reply
- 1:25:45while replying is probably
- 1:25:49not ideal name so I will call it reply
- 1:25:54just reply
- 1:25:56like this
- 1:25:58rip
- 1:26:00l y
- 1:26:03here we go let's do this
- 1:26:06okay perfect and from the comment item
- 1:26:09I'm going to also specify reply true and
- 1:26:12then in the comment create I'm going to
- 1:26:15specify reply true okay let's check this
- 1:26:19perfect I click on reply and look at
- 1:26:22this so now we already have a submit and
- 1:26:26cancel buttons visible so because this
- 1:26:28Focus was already set to be true and
- 1:26:33we can also do the same thing like we
- 1:26:37are doing here if this is edit or
- 1:26:42um
- 1:26:42this is focused then we run a focus not
- 1:26:48sure what this will do when we focus so
- 1:26:52basically when we are focusing uh this
- 1:26:54image is not code so that's perfect
- 1:26:57that's perfect so whenever we click
- 1:27:00reply then it's automatically focused
- 1:27:04and now let's take care of saving the
- 1:27:07comment
- 1:27:08if it is reply also in the comment item
- 1:27:11we have to provide a parent comment
- 1:27:15right so in the comment create
- 1:27:19we need
- 1:27:21one additional
- 1:27:23one additional variable
- 1:27:26let's call this parent comment
- 1:27:30equals
- 1:27:32here in comment equals a null by default
- 1:27:40okay
- 1:27:43peer and comments equals null I'm going
- 1:27:45to Define this peer and comment here as
- 1:27:47well
- 1:27:52and I'm also thinking that
- 1:27:55maybe we don't even need this reply
- 1:28:00because whenever we pass peer and
- 1:28:01comment it automatically means that we
- 1:28:04are replying to something because we
- 1:28:05have parents
- 1:28:07okay let me try to remove this reply so
- 1:28:09I'm going to take these peer and comment
- 1:28:11in this parent comments equals parent
- 1:28:14comment so we don't need reply let's try
- 1:28:17to remove it from here and from here as
- 1:28:19well
- 1:28:20I'm going to remove it from here as well
- 1:28:22but instead I'm going to use
- 1:28:24adherent comment so if Peer and comment
- 1:28:27exists
- 1:28:29then focused true otherwise false in the
- 1:28:33comment item instead of passing reply
- 1:28:35I'm going to pass parent
- 1:28:38Dash comment equals
- 1:28:42the current comment
- 1:28:44which we can access from anywhere in
- 1:28:47this component
- 1:28:48now let's double check this so
- 1:28:51everything works so far previously
- 1:28:53as it was working previously now click
- 1:28:56reply and we're in the focus mode which
- 1:28:58is excellent now I type something and
- 1:29:01whenever I click submit which is inside
- 1:29:03the comment create
- 1:29:06here
- 1:29:07let's first take care of this creation
- 1:29:10so here we need to check
- 1:29:12basically I can do like this
- 1:29:16hearing ID
- 1:29:18equals these here in comments question
- 1:29:22mark Arrow ID so if this parent comment
- 1:29:25exists it's going to take its ID if it
- 1:29:27doesn't exist it's going to provide
- 1:29:30um
- 1:29:31it's going to provide a null and then we
- 1:29:35trigger comment create and I have
- 1:29:37question now where this comment new
- 1:29:39comment will appear
- 1:29:41I think it will appear at the top right
- 1:29:44here because we don't
- 1:29:45we don't render it as a tree okay I'm
- 1:29:49going to click let's just reload and
- 1:29:51click reply and type something and click
- 1:29:54submit
- 1:29:56okay we have another
- 1:29:57let's see
- 1:30:01uh Integrity consumer okay compost ID
- 1:30:03cannot okay post ID cannot be null we
- 1:30:06don't provide post right so we have to
- 1:30:09provide post here and that will be
- 1:30:11comment
- 1:30:13post
- 1:30:15by the way comment I think doesn't have
- 1:30:17relation to post so let's open comment
- 1:30:19dot PHP
- 1:30:22let's duplicate these
- 1:30:26post belongs to post
- 1:30:30okay this is perfect
- 1:30:34now let's just rule the page click reply
- 1:30:37something
- 1:30:39and click submit and this is exactly
- 1:30:42what I was expecting so the new comment
- 1:30:43was created it appeared at the very top
- 1:30:46this is something when to handle second
- 1:30:48is that this leave a comment needs to be
- 1:30:51hidden
- 1:30:52so in the comment create
- 1:30:55when the comment is actually created and
- 1:30:59that comment create is called from the
- 1:31:01comment item from here
- 1:31:03so in the comment item
- 1:31:06let's open comment item we have
- 1:31:08listeners
- 1:31:10editing and update so I'm going to
- 1:31:13duplicate this line and add one more
- 1:31:15listener which will be comment created
- 1:31:18so if the comment created function is
- 1:31:21called on the comment item it definitely
- 1:31:25means that we are creating child comment
- 1:31:28if comment created is triggered from
- 1:31:30here
- 1:31:31this component has nothing related to
- 1:31:34comment item right but this component is
- 1:31:38inside the comment Act now whenever
- 1:31:41comment created is triggered and this
- 1:31:43function is called in the comment item
- 1:31:44we are sure that a child comment it was
- 1:31:48just created
- 1:31:49so what we need to do
- 1:31:52is first set this replying to be false
- 1:31:59let's do like this
- 1:32:01and this will basically hide the
- 1:32:05hide the input completely Let's test
- 1:32:08this so far test click submit okay that
- 1:32:11was hidden and now the parent component
- 1:32:14which is a comments component needs to
- 1:32:18handle rendering the comments properly
- 1:32:21all right let's check comments table
- 1:32:27and have a look we have parent ID on two
- 1:32:31comments
- 1:32:32excellent now let's open comments dot
- 1:32:35PHP
- 1:32:37here we are selecting the comments
- 1:32:41on Mount
- 1:32:43okay I'm going to extract this in its
- 1:32:46own function called select comments
- 1:32:51like this and we have the select
- 1:32:53comments at the very very bottom
- 1:32:57right here
- 1:33:00okay and I'm gonna do
- 1:33:03now the following so the comment
- 1:33:07uh whenever we are iterating and
- 1:33:09rendering comments we use couple of
- 1:33:11things we use comment post so we need
- 1:33:14with
- 1:33:16post we are using also comment user so
- 1:33:20we need user as well user single user
- 1:33:24now let's open comment model and we also
- 1:33:27need
- 1:33:28child comments
- 1:33:30so the comment basically has comments as
- 1:33:34well and that will be has many
- 1:33:38okay and how is it related so comment
- 1:33:43class by the foreign key will be
- 1:33:48by parent ID
- 1:33:52I think that should be like this so
- 1:33:54let's just remove this belongs tool it's
- 1:33:56not accurate and let's just return
- 1:33:59his menu
- 1:34:02but we also need belongs to which will
- 1:34:05be peer and comment
- 1:34:07I'm not sure whether we need this or not
- 1:34:09but let's just Define parent comment
- 1:34:14and this is belongs to belongs
- 1:34:20to
- 1:34:23belongs to
- 1:34:25yeah so it should be this will be
- 1:34:28belongs to comment by the foreign key
- 1:34:32okay not sure if this is 100 correct
- 1:34:35let's see if this works otherwise I can
- 1:34:38double check that so we have comments
- 1:34:40and now in the comment item when we
- 1:34:43iterate
- 1:34:44okay right here I am going to print the
- 1:34:49current comment
- 1:34:51comments which will give me all the
- 1:34:53children comments of the current comment
- 1:34:56let's have a look empty array empty
- 1:34:57array and here I have two comments then
- 1:35:00always I have empty array and this is
- 1:35:02perfect this is exactly what I expected
- 1:35:04now I'm going to open comments dot blade
- 1:35:09and I can simply grab this code and put
- 1:35:12this right here
- 1:35:15but change only these comments instead
- 1:35:18of these comments it's going to be
- 1:35:19comment
- 1:35:21comments
- 1:35:22and here also we can call this child
- 1:35:27comment
- 1:35:29all right now we're gonna pass these
- 1:35:31child comment here and we're going to
- 1:35:34also use child comment ID here
- 1:35:36now let's have a look
- 1:35:39I'm already so excited because we're
- 1:35:42very close to final things so here we
- 1:35:44have those comments
- 1:35:46I think we need some kind of
- 1:35:49uh like a margin padding things like
- 1:35:53that so I'm gonna put everything in its
- 1:35:56own div
- 1:35:58and let me actually first check
- 1:36:01um if comments
- 1:36:05effects exists if that's not empty
- 1:36:08basically then we call and if
- 1:36:12and let's give this one margin top
- 1:36:16four maybe
- 1:36:21uh okay so we need to check if that's
- 1:36:24not empty
- 1:36:25I thought that whenever you check these
- 1:36:28like in PHP I think when you check
- 1:36:29common comments if this is an empty
- 1:36:32array it's a falsible value and it will
- 1:36:35not render this code but I think this is
- 1:36:38rendering because for this there is no
- 1:36:41comment actually but here we see this is
- 1:36:44still the empty div so if not empty
- 1:36:53then
- 1:36:57okay e okay okay okay let's have a look
- 1:37:00this is probably collection and that's
- 1:37:02why it always satisfies so because this
- 1:37:05is a collection it should probably have
- 1:37:07like size Maybe
- 1:37:10okay it doesn't have size let's check
- 1:37:13size or length
- 1:37:20okay
- 1:37:22I want to get the length of the
- 1:37:24collection or count maybe you should
- 1:37:27probably have count
- 1:37:32let's see
- 1:37:34okay yes it has count
- 1:37:36and now these comments are child
- 1:37:39comments of these comments
- 1:37:41perfect so if I click reply now this
- 1:37:44appears right here
- 1:37:46another comment is written
- 1:37:50let's see click submit
- 1:37:54that another comment
- 1:37:57okay this is interesting another comment
- 1:38:00goes right here and right here
- 1:38:04that happens because
- 1:38:08this let's first see why it happens
- 1:38:13I'm going to open comments I think I
- 1:38:15don't have these comments dot PHP
- 1:38:18okay here here it goes no
- 1:38:22comment created here it goes so
- 1:38:24basically when the new comment is
- 1:38:25created it is edited at the very top of
- 1:38:27existing comments so that's why the new
- 1:38:30comment went right there then that
- 1:38:32caused re-rendering of this Live Wire
- 1:38:35component and during render phase we get
- 1:38:39the current comment comments and that's
- 1:38:41why we see the same comment twice added
- 1:38:44here and here as well
- 1:38:46okay let me do minor thing first the
- 1:38:50latest comment should be at the very top
- 1:38:51always if I just reload the page I see
- 1:38:54that this is at the very bottom so if I
- 1:38:56open this comment and this has has many
- 1:38:58now let's specify here order by disk
- 1:39:03uh created it
- 1:39:06underscore it
- 1:39:08reload the page and we see the latest
- 1:39:10comment at the very top
- 1:39:12okay next is to handle the scenario when
- 1:39:16that comment goes in a proper place
- 1:39:21this is this is important
- 1:39:24and that can be done
- 1:39:27through a flag I believe so in the from
- 1:39:31the comment create we emit these
- 1:39:34comment created and we pass this comment
- 1:39:37ID
- 1:39:38in the comment comments PHP we'll listen
- 1:39:43to that that select this comment
- 1:39:46and here we're going to check if the
- 1:39:49comment
- 1:39:51here and ID if that does not exist
- 1:39:55it means that this is a root level
- 1:39:57comment and it needs to be added in this
- 1:40:01array however if this has parent ID it's
- 1:40:05a child comment on something else and we
- 1:40:07should not do anything
- 1:40:09however the Livewire component will be
- 1:40:12re-rendered and then we will see
- 1:40:16then we will see it properly
- 1:40:19let's have a look
- 1:40:21this another comment why it appears
- 1:40:27um
- 1:40:29okay give me a second
- 1:40:32this test is here okay I see now we
- 1:40:36render right here all child and parent
- 1:40:39comments so we need to skip and remove
- 1:40:41child comments so we have these select
- 1:40:45comments and let's add here where
- 1:40:50parent ID
- 1:40:52we are null we are parent IDs now and I
- 1:40:56want to specify comments as well inside
- 1:40:59the with because I want to eagerly load
- 1:41:02post user and comments for every comment
- 1:41:07okay so far so good now let's try to add
- 1:41:10a new comment new comments let's click
- 1:41:14submit
- 1:41:15here we go here we go excellent so new
- 1:41:18comment was added right here let's click
- 1:41:21reply on that which in turn
- 1:41:24creates its own box inside there but I
- 1:41:28think we can even we need to completely
- 1:41:30probably disable that let's see we're
- 1:41:34gonna check also I noticed that when I
- 1:41:37click cancel it still stays in this uh
- 1:41:41the leave a comment still stays let's
- 1:41:43check how when to take care of this
- 1:41:47so here we have this create comment
- 1:41:49which is for
- 1:41:51replying
- 1:41:53and when we click cancel from inside
- 1:41:59where is that comment create
- 1:42:04okay cancel we call cancel editing
- 1:42:09okay and in the comment item
- 1:42:13we listen cancel editing and we set
- 1:42:18editing equals false but we also need to
- 1:42:22set
- 1:42:24replying equals
- 1:42:27replying equals false
- 1:42:32uh let's see so I click reply here that
- 1:42:36appears click cancel that disappears
- 1:42:39here we need to probably completely
- 1:42:41remove reply
- 1:42:45let's check what happens something
- 1:42:48click submit
- 1:42:52okay what is this
- 1:42:57just reload the page and we see this
- 1:43:00nested comment and you know what that
- 1:43:03works out of the box
- 1:43:06that works out of the box well the
- 1:43:09functionality is there and it's working
- 1:43:11which is really good
- 1:43:13however it's not going to be very very
- 1:43:17optimal
- 1:43:18uh like if you install the bug bar and
- 1:43:21have a look it's going to do a lot of
- 1:43:24requests
- 1:43:26to the database
- 1:43:29not sure if this is necessary or not and
- 1:43:32I think we have this functionality and
- 1:43:34we should probably spend a little bit
- 1:43:36more time to optimize it to make a less
- 1:43:38requests
- 1:43:41but also it's we should probably also
- 1:43:44have like pagination display only first
- 1:43:4620 comments and then Implement load more
- 1:43:49so there are a few things to do about
- 1:43:51the functionality is there and it's
- 1:43:54working
- 1:43:56which is really good
- 1:43:58I love it
- 1:44:01yeah the the update works like a charm
- 1:44:03so I'm going to click delete
- 1:44:05and the delete didn't work
- 1:44:08or maybe it worked but uh it wasn't
- 1:44:10re-rendered yes
- 1:44:12so if I click delete here it wasn't
- 1:44:15re-rendered if I click delete here that
- 1:44:19is removed okay I'm going to check
- 1:44:21what's going on when we click delete in
- 1:44:24the comment item
- 1:44:28here we have this delete it aim its
- 1:44:31comment deleted and we probably need to
- 1:44:34listen to comment deleted
- 1:44:40okay what do we do when this happens
- 1:44:45we are listening this inside comments
- 1:44:49and what do we do so we just filter the
- 1:44:54array
- 1:44:56so in this case
- 1:45:02let's just hit delete that's actually
- 1:45:04already deleted okay so when I click
- 1:45:07delete right here
- 1:45:10uh it filters out this list and we have
- 1:45:12new comments
- 1:45:14okay what do we need to do
- 1:45:17is this
- 1:45:21we are going to query the comment based
- 1:45:25on the ID
- 1:45:27and we are going to check
- 1:45:31if
- 1:45:33the comment
- 1:45:38if the comment parent ID
- 1:45:42exists if that doesn't exist then we
- 1:45:45filter and extract just reject the
- 1:45:50comment what was passed
- 1:45:53okay but however if the parent ID is set
- 1:45:57we shouldn't do this if I click delete
- 1:45:59right here
- 1:46:06let's see I'm going to click delete here
- 1:46:11okay attempt to read
- 1:46:16okay I see so it wasn't able to
- 1:46:20uh-huh yeah the comment was deleted and
- 1:46:24we passed ID right here we reject it but
- 1:46:31um but if we just try to select the
- 1:46:33comment that comment doesn't exist
- 1:46:34because we just deleted that comment so
- 1:46:36that was not correct what I did right
- 1:46:39now instead we just can refresh the
- 1:46:42whole comment section or just manually
- 1:46:46remove that comment from the child
- 1:46:49collection of that specific comment
- 1:46:53that is tricky thing so if I just
- 1:46:57revert this
- 1:47:02here
- 1:47:03and we can like keep tracking if the
- 1:47:08comment is
- 1:47:10if the comment was found and if that was
- 1:47:13rejected if it wasn't rejected we will
- 1:47:15assume that it is probably a child
- 1:47:18comment of another comment right and
- 1:47:22then we need to run this reject on a
- 1:47:26child comments
- 1:47:28which in my opinion can be done but it's
- 1:47:32going to be a little bit too complex so
- 1:47:35what I'm thinking right now is I will
- 1:47:37simply execute these select comments
- 1:47:40again
- 1:47:42so now let's have a look we don't have
- 1:47:45any child comments I just click delete
- 1:47:47and now we see the list so now I'm going
- 1:47:50to go ahead and delete those multiple
- 1:47:53comments I don't want all of them okay
- 1:47:56we have you know we have a lot of
- 1:47:58actually
- 1:48:03okay now let's Define child comment of
- 1:48:06this
- 1:48:07child comment one
- 1:48:12let's click submit here we see the child
- 1:48:14comment I reload the page it is there
- 1:48:16I'm going to Define another child
- 1:48:19comment
- 1:48:20uh child comment two click submit we see
- 1:48:24it right here now let's delete the child
- 1:48:26comment too
- 1:48:29well it was deleted I think
- 1:48:33but
- 1:48:35The View was not updated
- 1:48:38click on delete again it was deleted but
- 1:48:40the view was not updated
- 1:48:43okay I'm gonna double check if the code
- 1:48:45comes code execution comes right here
- 1:48:49when the comment is deleted for child
- 1:48:53like when when we delete a root level
- 1:48:55comment definitely code comes right here
- 1:48:57now let's define
- 1:48:59child
- 1:49:01comment one
- 1:49:04click on submit
- 1:49:07child comment two click on submit
- 1:49:11and now I delete this and well the code
- 1:49:17comes here and it's there and there no
- 1:49:20there's no error that's just our dump in
- 1:49:23the die
- 1:49:26okay so these should update the comment
- 1:49:29section it is reselecting the comments
- 1:49:35however it still includes the new
- 1:49:38comments or just a view does not update
- 1:49:41properly
- 1:49:45click on delete
- 1:49:47okay it does not update The View
- 1:49:50okay so what I think we can do here that
- 1:49:54instead of calling this comment deleted
- 1:49:57here we can call refresh which is a live
- 1:50:02wire
- 1:50:03keyword so call it so if I just remove
- 1:50:06this comment deleted completely whenever
- 1:50:10comment is deleted it's going to call
- 1:50:11refresh refresh will obviously do the
- 1:50:15entire like probably Mount as well which
- 1:50:17will select comments and everything so
- 1:50:20it should work
- 1:50:21now let's Define child one
- 1:50:25and let's Define child two submit now
- 1:50:31I'm going to try to delete this
- 1:50:34and it does not do
- 1:50:37the refresh
- 1:50:39is I expected
- 1:50:44no it doesn't refresh
- 1:50:47it does however
- 1:50:50like even if I completely remove this
- 1:50:52comment deleted
- 1:50:55and add
- 1:51:00comment one
- 1:51:04comment two
- 1:51:08comment three
- 1:51:11okay I know I don't have I'm I don't
- 1:51:14listen to delete and if I click on
- 1:51:17delete now it doesn't do anything
- 1:51:20okay so if I add this it's gonna do
- 1:51:23re-refresh
- 1:51:25or refresh so I click on delete and it's
- 1:51:28going to do refresh if I create child
- 1:51:31comment 1 child comment two then if I
- 1:51:34just rule the page entirely and then
- 1:51:36click delete it does not do this refresh
- 1:51:42if I click delete again we're going to
- 1:51:44have an error because that was actually
- 1:51:46already deleted
- 1:51:50hmm
- 1:51:53this is actually strange
- 1:51:59okay what I think maybe maybe eloquent
- 1:52:04um saves all the child comments in its
- 1:52:07own cache like when we select these
- 1:52:10comments
- 1:52:13on Mount basically and let's double
- 1:52:16check by the way if Mount is called on
- 1:52:19refresh
- 1:52:21so I save these
- 1:52:23and now I click delete on this
- 1:52:28okay Mount is not called Mount is called
- 1:52:32right here
- 1:52:36okay I think Simple Solution here and I
- 1:52:39think also correct solution here will be
- 1:52:42to put these comments again in the
- 1:52:45render and every time there's there's
- 1:52:48comment created or deleted this render
- 1:52:51method will be called and it's gonna
- 1:52:53reselect everything and render them
- 1:52:55properly okay I tried to create a kind
- 1:52:58of optimal solution that whenever new
- 1:53:00comment is created we just add this in
- 1:53:02existing comments array and don't select
- 1:53:05entire list of comments but I think uh
- 1:53:09it's fine in in the future we might even
- 1:53:11need to add pagination and display just
- 1:53:1320 comments and then load more so
- 1:53:15selecting 20 comment is not a big deal
- 1:53:18so what I think now is I'm going to grab
- 1:53:21this
- 1:53:21and here I'm going to select the
- 1:53:24comments in the vein I'm going to pass
- 1:53:28these
- 1:53:29comments here I'm going to remove these
- 1:53:32comments array completely and whenever
- 1:53:34comment is created uh I'm gonna call
- 1:53:38also
- 1:53:40refresh
- 1:53:42like this
- 1:53:43whenever comment is created your comment
- 1:53:45is deleted it's going to call refresh
- 1:53:47now let's check how this will work
- 1:53:50reload the page
- 1:53:53test comment
- 1:53:56hit submit it is edit perfect
- 1:54:00another comment
- 1:54:02click submit it is edit right here
- 1:54:04perfect now let's reply one click submit
- 1:54:09it is here two submit it is here now
- 1:54:13let's delete peer and comment first
- 1:54:16that will still eat it another comment
- 1:54:18delete it perfect now let's delete child
- 1:54:20comment
- 1:54:21now it still stays
- 1:54:25come on
- 1:54:29so I'm sure these render is actually
- 1:54:31called so we can double check this
- 1:54:36let's see render is called obviously
- 1:54:39right here so I'm going to comment this
- 1:54:40line
- 1:54:42and reload the page
- 1:54:44and let's add one and add two now I'm
- 1:54:48going to uncomment this and if I delete
- 1:54:51one comment then render is called
- 1:54:56and that should not have this comment
- 1:54:58anymore
- 1:54:59so I'm gonna
- 1:55:01dump
- 1:55:04these comments
- 1:55:06here more specifically I'm going to dump
- 1:55:09the first comment from here
- 1:55:12let's see
- 1:55:17uh hold on
- 1:55:21so I'm going to delete this
- 1:55:25and then I'm going to dump these
- 1:55:27comments and check what is its comments
- 1:55:30property
- 1:55:31so let's click delete here here we go it
- 1:55:35has attributes
- 1:55:37and
- 1:55:39we are interested in
- 1:55:41relations
- 1:55:43comments
- 1:55:45items
- 1:55:47which is obviously
- 1:55:51zero it doesn't have length
- 1:55:54so then this renders the comments
- 1:55:57section
- 1:55:58let's open
- 1:56:01uh comments section comments dot blade
- 1:56:06then comment create and comment item if
- 1:56:09we open now comment item
- 1:56:12here we get the comment
- 1:56:16comments count I'm going to print what
- 1:56:19is the count CH those are the child
- 1:56:23common count
- 1:56:25and those are the actual child comments
- 1:56:27I'm going to also print if there are
- 1:56:30those child comments here
- 1:56:33and maybe I need to
- 1:56:36remove this
- 1:56:39Let's test
- 1:56:41zero child comments fine one there's one
- 1:56:44child comment two there are two children
- 1:56:47comments
- 1:56:49okay these has
- 1:56:51no this is just two okay so far so good
- 1:56:54now I delete these comments
- 1:56:59this is till 2 and this does not change
- 1:57:05okay
- 1:57:08I think it's
- 1:57:09this is related to Live Wire not the
- 1:57:14live wire but still arrival so let's
- 1:57:16search for laravel
- 1:57:19um
- 1:57:21objects
- 1:57:23is cached something like this
- 1:57:30okay I want to basically re reselect the
- 1:57:36laravel
- 1:57:37component
- 1:57:40let me actually make sure that this is
- 1:57:43definitely a problem so that's why here
- 1:57:45I have one comment
- 1:57:47and before I hit the delete button here
- 1:57:49I'm going to take this and print
- 1:57:53comments eight zero
- 1:57:57comments so these will be child comments
- 1:58:01so I save that
- 1:58:04and click on delete
- 1:58:07now this gives me
- 1:58:09collection with items empty
- 1:58:14and I don't see anything there
- 1:58:17which is correct right
- 1:58:21but somehow
- 1:58:25it is not correct
- 1:58:29what about count
- 1:58:31what are the child children common count
- 1:58:34so I'm going to find one
- 1:58:36and two
- 1:58:38now let's delete this one child comment
- 1:58:42count is one which is correct
- 1:58:46reload the page
- 1:58:50now there's one comment
- 1:58:52I uncomment this line and click on
- 1:58:55delete now there's zero comment however
- 1:58:59if I proceed
- 1:59:03if I proceed then it has
- 1:59:09very very very very very strange
- 1:59:14this is a comment
- 1:59:20maybe the component is cached because
- 1:59:24because of this ID
- 1:59:26so the ID does not change
- 1:59:29right
- 1:59:31maybe that is cached and what if I print
- 1:59:35right here comment
- 1:59:40comments common comments okay let's
- 1:59:42print that those are children comments
- 1:59:48okay now there are zero trillion
- 1:59:51comments I'm gonna need one
- 1:59:52here we see one
- 1:59:55let's add one more
- 1:59:58okay here we see that
- 2:00:01now I delete these
- 2:00:04okay here it was changed but not here
- 2:00:08and then I delete this now this cleared
- 2:00:11up
- 2:00:12pay attention
- 2:00:14this still contains
- 2:00:20because the comment ID
- 2:00:23was not properly changed here here is
- 2:00:26the problem
- 2:00:28what if I specify right here e to be
- 2:00:33comments
- 2:00:36comment
- 2:00:40hold on
- 2:00:42comments count
- 2:00:45so the key
- 2:00:47of that specific component
- 2:00:51will be comment the comment ID as well
- 2:00:54as the number of comments this has so if
- 2:00:59it increases or decreases it will force
- 2:01:02the live wire to re-render that specific
- 2:01:07component
- 2:01:10well that's a clever idea but let's see
- 2:01:13if that works in action so I reload the
- 2:01:16page I hit one
- 2:01:17I had two now I delete this and it
- 2:01:22worked
- 2:01:23and it worked
- 2:01:28okay amazing
- 2:01:30and if so far you're watching this and
- 2:01:33you haven't clicked a like button I
- 2:01:35think it's perfect time to pause the
- 2:01:38video hit the like button I will be very
- 2:01:40very thankful
- 2:01:42to you
- 2:01:43okay so now leaving comments as a
- 2:01:46children comment editing that
- 2:01:49deleting that comment
- 2:01:51deleting every comment everything
- 2:01:54basically works perfectly as it it is
- 2:01:57supposed to work
- 2:02:00now I'm going to Define one Global
- 2:02:03search input field and then search
- 2:02:05basically everywhere
- 2:02:09um let's open
- 2:02:11up Blade the main layout file
- 2:02:17and I want to Define this below header
- 2:02:21below top nav
- 2:02:23probably right here inside the container
- 2:02:26so if I just type input
- 2:02:29and this is it
- 2:02:31however I want this to be
- 2:02:34now this has display Flex
- 2:02:38and flex drop which I'm going to remove
- 2:02:40if you don't mind
- 2:02:43okay let's
- 2:02:45that's okay
- 2:02:47and this is the input field which
- 2:02:52which I want to show on the full width
- 2:02:56also the container with this too much
- 2:02:59maybe
- 2:03:00so I want to show this on a full width
- 2:03:03so I'm going to get the input from
- 2:03:08comment create
- 2:03:10comment slash create here we have this
- 2:03:14text area so I'm gonna
- 2:03:16grab that and paste here
- 2:03:19now let's adjust let's remove this fire
- 2:03:22model and click
- 2:03:24let's remove xref
- 2:03:26I'm gonna change this into
- 2:03:30input
- 2:03:31and let's remove rows
- 2:03:36um type
- 2:03:37and hit enter
- 2:03:41to search anything
- 2:03:44so yeah something like this
- 2:03:49okay here we see that it has
- 2:03:53like
- 2:03:55some weird
- 2:03:57styles to be honest
- 2:03:59if you zoom in a lot
- 2:04:03it has two colors
- 2:04:09why does it have those two colors
- 2:04:13if I inspect that
- 2:04:16and right click and focus
- 2:04:20it has also
- 2:04:23active
- 2:04:24what's that
- 2:04:32that's really really really strange
- 2:04:37where does this Blick
- 2:04:42something is coming from
- 2:04:45okay what if I remove this ring gray 300
- 2:04:50but if I remove all those classes
- 2:04:53like everything
- 2:04:56let's see
- 2:04:58we have black
- 2:05:04text Gray 900 fine
- 2:05:08ring gray 300 and when we type inside
- 2:05:14it's gonna have ring integral
- 2:05:18as save this and we see this input
- 2:05:21however again like it's strange
- 2:05:25um I'm not gonna spend too much time on
- 2:05:28this maybe I can remove all the Indigo
- 2:05:31ring classes
- 2:05:35that behaves really strangely for me
- 2:05:40but I'm gonna leave it as it is
- 2:05:44let's give it padding three and I'm
- 2:05:46going to put this inside
- 2:05:48padding three and now whenever I type
- 2:05:52something and hit the enter
- 2:05:55once the search to filter only those
- 2:06:00articles which filter the uh which
- 2:06:03satisfy the following filtering criteria
- 2:06:05okay so let's Implement first
- 2:06:08uh form so I'm going to create form
- 2:06:12inside there we're going to have
- 2:06:15um we don't need button I think but we
- 2:06:18might need so I have a doubt that if you
- 2:06:21don't have a button and you just try to
- 2:06:23submit the form without button it's not
- 2:06:25gonna work
- 2:06:26let's give it method method should be
- 2:06:29get
- 2:06:30action can be current road
- 2:06:33so we just specify
- 2:06:36yeah we can leave this empty actually
- 2:06:38action and now if I let's give this name
- 2:06:43name just Q
- 2:06:47and if I type something like JavaScript
- 2:06:50and hit the enter it filters and we see
- 2:06:53Q JavaScript
- 2:06:55and now we need to
- 2:06:58only match those
- 2:07:00articles which has JavaScript right
- 2:07:02there
- 2:07:04okay but we also need in my opinion like
- 2:07:07a dedicated search page so what I'm
- 2:07:11going to do is open web.php
- 2:07:15and let's define one additional root
- 2:07:18here that's going to be search
- 2:07:21the road will be searched
- 2:07:25this will be search
- 2:07:27so in this case I'm going to specify
- 2:07:29roads
- 2:07:31to be searched
- 2:07:34perfect
- 2:07:37and let's open this home or maybe like
- 2:07:41another one which is by category
- 2:07:45and I'm going to duplicate this
- 2:07:47let's call this search we don't have
- 2:07:50category
- 2:07:51we have request here
- 2:07:57and we're going to get
- 2:07:59a q from request
- 2:08:03um
- 2:08:05get
- 2:08:07Q
- 2:08:10okay and now we need to filter
- 2:08:14the posts which satisfy the following
- 2:08:17criteria and we also need pagination I
- 2:08:21think
- 2:08:23so I'm going to get these posts
- 2:08:32let's remove this join and where we need
- 2:08:36active published order by published it
- 2:08:40but the main thing is that we have to
- 2:08:43specify where
- 2:08:48title
- 2:08:50like
- 2:08:52our given
- 2:08:55you so in this case
- 2:08:59um it should be in
- 2:09:03like this I believe title like this and
- 2:09:07then we pass
- 2:09:09posts
- 2:09:11but I will want to pass this into
- 2:09:14post not post index
- 2:09:18on search for post Index this is it but
- 2:09:21instead I want post search Maybe
- 2:09:25so I'm gonna copy and paste this post
- 2:09:27index and call this search
- 2:09:32okay I'm gonna use
- 2:09:35post search here
- 2:09:38passing the posts
- 2:09:40and we have these post links which
- 2:09:43which is fine which will be the same
- 2:09:45type of next and previous links as we
- 2:09:46had before which is okay
- 2:09:48so the this is a search page we can
- 2:09:52specify like uh Log search meta titles
- 2:09:55I'm going to remove this
- 2:09:58you can specify if you want
- 2:10:01and now we have those posts which I'm
- 2:10:03not going to render
- 2:10:06I'm going to render it slightly
- 2:10:08differently maybe but let's first check
- 2:10:11if the actual searching works like I'm
- 2:10:14going to type JavaScript here hit the
- 2:10:16enter
- 2:10:17and I find variable category
- 2:10:22okay where does it go
- 2:10:28I deleted this from index I had to
- 2:10:31delete this from
- 2:10:32search
- 2:10:36okay whatever is in the URL
- 2:10:40I have to put this in this input field
- 2:10:42as well
- 2:10:44so in the up blade
- 2:10:46I'm going to give this value
- 2:10:50request
- 2:10:54it
- 2:10:55you
- 2:10:58here we see JavaScript if I go on home
- 2:11:00page I don't see anything here
- 2:11:03type JavaScript hit the enter
- 2:11:06and it filters only one post which is
- 2:11:10awesome
- 2:11:11however I'm going to change the
- 2:11:13rendering as I mentioned so instead of
- 2:11:15using post item here
- 2:11:17I'm going to do it a very simple like H2
- 2:11:20that's going to be post
- 2:11:24that's going to be post title
- 2:11:29div we're going to Output
- 2:11:34host
- 2:11:36short body Maybe
- 2:11:39like this
- 2:11:42okay this needs to be
- 2:11:47this needs to be in the not not in the
- 2:11:50center so maybe I can remove these items
- 2:11:53Center not necessary
- 2:11:56that's good and let's specify here
- 2:12:00text blue 500 font pulled
- 2:12:06text LG above small screen it's going to
- 2:12:12be
- 2:12:12text EXO
- 2:12:17okay maybe margin button 2 as well
- 2:12:22but whenever we click on this it needs
- 2:12:25to open its inner page
- 2:12:28so we need to Define
- 2:12:32roads
- 2:12:35or View
- 2:12:37and provide an actual post
- 2:12:42okay so far so good now let's search for
- 2:12:46something like Alice and we see multiple
- 2:12:50Alice let's
- 2:12:53let's remove Flex completely and give
- 2:12:56this margin bottom eight Maybe
- 2:13:02this doesn't seem to be working no I
- 2:13:05should not have specified it here I
- 2:13:08should have wrapped everything in zone
- 2:13:10div and give this one
- 2:13:14class margin button 8.
- 2:13:19we can even use HR
- 2:13:25and completely remove these and give
- 2:13:28this HR class
- 2:13:31a margin vertical four maybe
- 2:13:36that's that's good so now we have this
- 2:13:41which is excellent
- 2:13:43well
- 2:13:45there might be like again I'm going to
- 2:13:48give you a challenge
- 2:13:51right now we see that Ali's keywords are
- 2:13:54matched in many places
- 2:13:57it's going to be awesome if you actually
- 2:13:58highlight
- 2:14:00all the matchings which are there
- 2:14:03and make it like actually actually
- 2:14:06yellow for example so we are about how
- 2:14:10to Output the title here what we can do
- 2:14:14is call Str replace
- 2:14:18on this post title and search for
- 2:14:24search for
- 2:14:26the keyword actual keyword which which
- 2:14:28will be
- 2:14:29request
- 2:14:33request
- 2:14:36get Q
- 2:14:40replace it with something else inside
- 2:14:43here so in this case I'm just replacing
- 2:14:45with the empty string and this should
- 2:14:47remove all the Alice matchings and it
- 2:14:49definitely removed from title but
- 2:14:51instead of
- 2:14:53replacing with empty string you should
- 2:14:55replace it with something like span
- 2:15:00I'm actually doing this but um I'm going
- 2:15:02to give you additional challenge
- 2:15:04right now
- 2:15:06span class
- 2:15:09we're gonna give it
- 2:15:11a PG
- 2:15:13yellow
- 2:15:16400 something like this now let's see
- 2:15:21okay we are going to Output these
- 2:15:26is an HTML I don't remember how to do
- 2:15:31this by heart so laravel output
- 2:15:34HTML
- 2:15:38this is how I should do this yeah
- 2:15:46so I save this and look at this so now
- 2:15:50this is all the matching 400 is maybe
- 2:15:52too much 300
- 2:15:55okay so here are the matchings you can
- 2:15:58easily identify you can do something
- 2:16:00similar in body as well but the point is
- 2:16:04that
- 2:16:05if there is matching in the body it
- 2:16:08might not be in this short body it might
- 2:16:11be in the long body if I open this and
- 2:16:14search for
- 2:16:15like this keyword begin to repeat it
- 2:16:18okay I type this here
- 2:16:21hit the enter
- 2:16:22and it doesn't find anything because we
- 2:16:26don't search actually in the body but we
- 2:16:29have to do this so let's duplicate this
- 2:16:31where or
- 2:16:34where
- 2:16:36I'm going to specify now body like the
- 2:16:39given keyword
- 2:16:40so now if I type the following text hit
- 2:16:43the enter it finds few things but we
- 2:16:47don't see anything in yellow simply
- 2:16:49because
- 2:16:50the matching is outside of this short
- 2:16:52body okay as a challenge and it's pretty
- 2:16:57um like interesting challenge
- 2:16:59you can change what is actually output
- 2:17:02is right here so at the moment we just
- 2:17:05take first like 30 words
- 2:17:08but based on an actual matching
- 2:17:11it is somewhere right here try to Output
- 2:17:14from previous sentence like from here
- 2:17:18to whatever
- 2:17:20here or here so take the highlighted
- 2:17:24section and output that in the search
- 2:17:27instead of the first few sentence first
- 2:17:30few words whatever
- 2:17:34I hope you get the idea and
- 2:17:37yeah
- 2:17:39so let's see if the search actually does
- 2:17:42the job on other pages I want to reduce
- 2:17:44the width of the search just like we
- 2:17:46have this on home page so I'm going to
- 2:17:48open the home and you'll have the max W4
- 2:17:52Excel I'm going to do the same thing
- 2:17:54let's give this Max W and let's give it
- 2:17:58a m x
- 2:18:00Auto
- 2:18:03save reload
- 2:18:05this is how I want that
- 2:18:07and I'm going to type
- 2:18:10again something
- 2:18:12that binds and it is clickable
- 2:18:16okay
- 2:18:18by the way why this is not found are we
- 2:18:22searched for in non-active
- 2:18:29okay yes so this or we're basically is
- 2:18:34or wear for everything else
- 2:18:36so we need
- 2:18:39those two
- 2:18:42those two to be inside
- 2:18:45well I'm going to do like this
- 2:18:48we're
- 2:18:52function we get query
- 2:18:57and then I add like this
- 2:19:05and we need to use the
- 2:19:08queue here
- 2:19:10so where title is like this or what is
- 2:19:14this so now we should not see
- 2:19:18so many well we see so many if I click
- 2:19:22that works click that works
- 2:19:25I guess all of them works so we have
- 2:19:28successfully implemented
- 2:19:31our search and we also have
- 2:19:34those pagination buttons as well
- 2:19:38if I go in the larval page
- 2:19:42I'm looking at the laravel articles I
- 2:19:44can't even start typing from here and
- 2:19:46search for something else which
- 2:19:50should actually filter
- 2:19:54based on the category and then based on
- 2:19:56the keyword as well
- 2:20:00so this is something also to consider so
- 2:20:03if I click on if I'm on a view page
- 2:20:07I probably should not see that
- 2:20:10or if we assume that this is a global
- 2:20:12search
- 2:20:15which by the way I don't like where it
- 2:20:17is right now so I'm thinking maybe I
- 2:20:20need to grab that
- 2:20:21nice form
- 2:20:23and put these
- 2:20:27put these
- 2:20:29hmm
- 2:20:31maybe here
- 2:20:40what if we'll leave it here
- 2:20:45let's give it a Class A font normal
- 2:20:50or medium
- 2:20:56okay I think
- 2:20:58um like I want it to be there
- 2:21:01inside the teeth to be on the right side
- 2:21:04let's give this one
- 2:21:06Flex a line items Center
- 2:21:13now let's search for JavaScript and
- 2:21:15every time now this is this makes more
- 2:21:17sense every time whenever we type
- 2:21:19something here it is in the header and
- 2:21:21that will always redirect us to the
- 2:21:23search page even if you are on laravel
- 2:21:26if even if you are searching for a PHP
- 2:21:28or whatever you type something again and
- 2:21:32you are redirected to the search page so
- 2:21:36that's a global global search on your
- 2:21:39website
- 2:21:47however when you
- 2:21:49click and then go back it's preserved
- 2:21:53okay fine delete functionality works
- 2:21:57now let's deploy our project on
- 2:21:59production environment with custom
- 2:22:01domain when you sign up on hostinger and
- 2:22:04then login you will be redirected to the
- 2:22:06age panel from here we can claim our
- 2:22:09free domain
- 2:22:10you're going to see the following
- 2:22:12section if you signed up with premium
- 2:22:13shared hosting then click this claim
- 2:22:16domain and then right here we need to
- 2:22:18provide our domain name so in this case
- 2:22:20this is going to be like a my personal
- 2:22:22blog type of website so I'm going to
- 2:22:26choose like the code
- 2:22:28holique.net this is I'm sure this is
- 2:22:31going to be free so let's check
- 2:22:32availability so here we go the domain is
- 2:22:35available the codeholic.net that's
- 2:22:37perfect domain for me I already own
- 2:22:39codholic.com by the way if you want to
- 2:22:41check that feel free to check you can
- 2:22:43find laravel e-commerce course right
- 2:22:45there
- 2:22:46now I'm going to click claim domain
- 2:22:49choose your domain carefully because
- 2:22:51like you aren't going to be able to
- 2:22:53change it easily then right here if
- 2:22:55you're doing this very first time you
- 2:22:56have to provide your profile information
- 2:22:58such as your address and email and
- 2:23:01things like that I already have a
- 2:23:03profile existing profile so I'm going to
- 2:23:05just click finish registration
- 2:23:08now it will ask me a few more steps I'm
- 2:23:10going to click continue and here we go
- 2:23:13my domain is already available so I'm
- 2:23:15going to just copy this and open new tab
- 2:23:18hit the enter and you should see the
- 2:23:20following page the code.net happy to see
- 2:23:23your domain with hostinger since we
- 2:23:25claimed our domain now we need to set up
- 2:23:27our web hosting I'm going to click on
- 2:23:30the home logo and then I'm going to
- 2:23:32choose this premium web hosting let's
- 2:23:34click setup start now
- 2:23:37I'm going to skip basically everything I
- 2:23:39want to create everything from scratch
- 2:23:42create new websites so I'm going to
- 2:23:44click skip right here as well so here I
- 2:23:46have option to choose a domain and in
- 2:23:49this case I'm going to choose the
- 2:23:50codeholic.net and I'm going to click
- 2:23:53select now I need to choose a location
- 2:23:55and you can choose a one location from
- 2:23:59like which is probably close to you and
- 2:24:02then I'm going to click finish setup now
- 2:24:04let's scroll down below you will need to
- 2:24:07wait couple of seconds or maybe two
- 2:24:09minutes until the whole process is done
- 2:24:11SSL is going to be installed as well
- 2:24:13automatically and the web server will be
- 2:24:15configured for your domain now I'm going
- 2:24:18to click this Wii U website and it's
- 2:24:20going to open our domain however it is
- 2:24:23still not under SSL so it might take a
- 2:24:26few seconds or minutes
- 2:24:28to make this SSL actually working
- 2:24:31however we can click this manage site
- 2:24:34and check what's the SSL status status
- 2:24:37the very moment this is the control
- 2:24:39panel from which you can manage your
- 2:24:42domain and anything basically related to
- 2:24:45The Domain from here in the search I can
- 2:24:47search for SSL and we can see what's
- 2:24:50this current status of this SSL
- 2:24:53and right now it is in the installing
- 2:24:55process you're going to wait for like a
- 2:24:57two or three minutes until this is fully
- 2:24:59installed if it is failed then you will
- 2:25:01have an action to retry installing that
- 2:25:04sometimes it fails on the first try but
- 2:25:07then it installs without any problem and
- 2:25:09I already got a notification that it was
- 2:25:11successfully installed so if I open my
- 2:25:13domain and just reload I see now my
- 2:25:17domain is under SSL now if we go in this
- 2:25:20control panel right here we have much
- 2:25:22more options I really recommend to check
- 2:25:25that if we're gonna use hot singer's
- 2:25:26premium shared Housing Services because
- 2:25:28they offer huge configuration options
- 2:25:30like what I'm interested right now is to
- 2:25:33switch PHP version to the latest one I'm
- 2:25:36going to click PHP configuration right
- 2:25:38here and then I have couple of options
- 2:25:40and I'm going to choose PHP 8.1 and I'm
- 2:25:44going to click update
- 2:25:46I'm going to confirm now we have
- 2:25:48switched PHP version to 8.1 and now we
- 2:25:52can already log into this server using
- 2:25:54SSH and we can clone our project in
- 2:25:58search I'm going to type SSH click SSH
- 2:26:01access
- 2:26:02here we have the details for our SSH
- 2:26:05server first of all pay attention that
- 2:26:07SSH status is inactive so we need to
- 2:26:10click enable right here then this is the
- 2:26:13IP port username and we need to set
- 2:26:15password I recommend to set very secure
- 2:26:17password
- 2:26:19let's set something
- 2:26:21okay I'm going to click change my stage
- 2:26:25password was saved it is even
- 2:26:27recommended to use public private key
- 2:26:31authentication when connecting to a
- 2:26:34search server so if you know what is
- 2:26:36that and if you have public key
- 2:26:38generated I really encourage you to
- 2:26:40click add SSH key right here provide
- 2:26:42your public key click and add SSH key
- 2:26:45and then you will be authorized to the
- 2:26:47server through SSH now I'm going to copy
- 2:26:50the following command
- 2:26:51and I'm going to open Powershell
- 2:26:56Windows Powershell
- 2:26:58and I'm going to paste the comment right
- 2:27:00here Windows Powershell by default
- 2:27:02supports SSH it's also a sh client if
- 2:27:05you are on Mac or on Linux probably your
- 2:27:08terminal will also support SSH so right
- 2:27:12here I'm trying to execute SSH Common
- 2:27:14with Port this is the username and this
- 2:27:16is the IP let's click enter
- 2:27:20we have to type yes here
- 2:27:22and I'm going to provide now my password
- 2:27:29probably I made a mistake
- 2:27:33okay here's my pass um here's my SSH
- 2:27:36server so I'm inside the server now
- 2:27:39let's let me actually zoom in this
- 2:27:41slightly if I go in the properties and
- 2:27:45font and let's increase that perfect now
- 2:27:49let's enlarge this on full screen and
- 2:27:52now let's have a look
- 2:27:54ls-le so this is it so the the whole
- 2:27:58project what you see in the browser is
- 2:28:00at the moment under public HTML folder
- 2:28:03and that public HTML folder is a
- 2:28:06symbolic link from the following path
- 2:28:09and that path is domains the code
- 2:28:12holic.net public HTML so it's a little
- 2:28:15bit hard to read this until you
- 2:28:18highlight that but that's the actual
- 2:28:20path where the
- 2:28:22HTML what is rendered right here right
- 2:28:27here is used so if I go right here and
- 2:28:31I'm going to delete this the
- 2:28:33codeholic.net completely so let's go
- 2:28:36inside domains folder using CD and I'm
- 2:28:40going to execute
- 2:28:41rm-rf
- 2:28:43the codeholic.net so I completely delete
- 2:28:46this folder and right now
- 2:28:50if I go back
- 2:28:52I have this public HTML which references
- 2:28:55to a broken non-existing folder so that
- 2:28:59public HTML should also be removed and
- 2:29:03now
- 2:29:05and now there is no public HTML if I go
- 2:29:08under domains
- 2:29:11there is nothing as well and if I check
- 2:29:14in the browser
- 2:29:16our website is actually broken okay now
- 2:29:19we need to clone our project let's click
- 2:29:22this code and I'm going to clone this
- 2:29:24through SSH click right here
- 2:29:27let's clear up everything and I'm going
- 2:29:29to clone this
- 2:29:31in a folder called the exact same name
- 2:29:35whatever is your domain okay whatever
- 2:29:37the folder previously existed you're
- 2:29:39going to create the exact same folder
- 2:29:42the code holic.net
- 2:29:46let's hit the enter
- 2:29:48okay that was cloned and if we check
- 2:29:51right now we see the code holy.net right
- 2:29:53here if we go inside the code holy.net
- 2:29:56and type ls-l-a we're going to see all
- 2:30:00the files and folders which are in our
- 2:30:02project now what we need to do is to
- 2:30:05create a symbolic link of public HTML
- 2:30:09which references to these public folder
- 2:30:13all right so I'm going to go back
- 2:30:17to directory so I'm going to go
- 2:30:19basically in my home folder where I
- 2:30:22previously had public HTML and I'm going
- 2:30:25to create reference Ln dash s I'm going
- 2:30:28to create
- 2:30:30um
- 2:30:31domains
- 2:30:32the code holy.net public that is the
- 2:30:36folder
- 2:30:37which I on which I want to create a
- 2:30:40symbolic link called public HTML
- 2:30:44okay let's hit the enter now if I type
- 2:30:47ls-l-a-ic public HTML which references
- 2:30:50to these public folder that public
- 2:30:53folder which is under the code.net is a
- 2:30:56public folder of a lateral project right
- 2:31:00now let's go inside domains
- 2:31:04like hotels.net and we're going to run
- 2:31:07composer install however whenever we
- 2:31:10type composer dash dash version
- 2:31:13we see that this one shows where is it
- 2:31:16version 1.10 and it also prints a lot of
- 2:31:20earnings that's because
- 2:31:22composer version is kind of outdated
- 2:31:25it's deprecated and for lateral
- 2:31:28especially we should be using composer
- 2:31:31version 2. we can't simply use composer
- 2:31:34version one so in the Google I'm going
- 2:31:36to type composer version 2. let's click
- 2:31:41download composer latest right here then
- 2:31:45we're going to copy the following four
- 2:31:47lines
- 2:31:48and paste them right here so it's going
- 2:31:51to basically execute those lines uh one
- 2:31:54after another let's hit enter finally
- 2:31:56and then now in our folder we will see
- 2:32:00composer far that composer far basically
- 2:32:04is the latest version for composer now
- 2:32:07whenever we want to run any composer
- 2:32:10command instead of typing composer like
- 2:32:13this we're going to type composer excuse
- 2:32:17me PHP composer dot far so that
- 2:32:21references a composer and if I type
- 2:32:24version we see version
- 2:32:272.5.15 so now we can execute PHP
- 2:32:31composer far install and let's wait so
- 2:32:35it's going to download all the
- 2:32:36dependencies our project needs and then
- 2:32:39install them locally
- 2:32:42okay that was done now let's generate
- 2:32:44key PHP artisan
- 2:32:48key generate a insi let's
- 2:32:53I think I made some kind of mistake PHP
- 2:32:56Artisan key generator station PSI
- 2:33:00okay so yeah we don't have enable it
- 2:33:03needs to put this in EN so we basically
- 2:33:06need to First create dot en file so
- 2:33:08let's run copy command and I want to
- 2:33:11copy end of example into dot enf okay
- 2:33:15after that we can already execute PHP
- 2:33:18art design key generate and the key set
- 2:33:21successfully which is awesome now let's
- 2:33:23create storage link PHP Artisan storage
- 2:33:27column link let's see the enter storage
- 2:33:30link connected
- 2:33:32and I think we are good we obviously
- 2:33:36need to connect to the database but
- 2:33:38before we do that let's check how our
- 2:33:41domain looks like okay so we have this
- 2:33:44problem again and this happens because
- 2:33:47we also need to have public HTML folder
- 2:33:50in our domain name like in the
- 2:33:54decode.net at the moment we don't have
- 2:33:57public HTML right so let's just create
- 2:34:00Ln
- 2:34:03is public folder needs to be linked into
- 2:34:07public HTML let's hit the enter okay now
- 2:34:11if we check we see public HTML which is
- 2:34:14a symbolic link into public folder and
- 2:34:17now if we check this
- 2:34:19here we go so this is larval error and
- 2:34:22that comes because we don't have
- 2:34:23connection to the database we don't have
- 2:34:25a proper connection and we don't we
- 2:34:28don't have anything related to database
- 2:34:30done yet so let's go in the our hosting
- 2:34:34provider into hostinger and let's
- 2:34:37type database right here let's click
- 2:34:40this is the database we can click page
- 2:34:43my admin or probably we should click
- 2:34:45management and we should create new
- 2:34:47database let's call this laravel 10
- 2:34:51underscore block we have to provide
- 2:34:54username as well and pay attention that
- 2:34:57this is going to be the prefix for your
- 2:34:58database name as well as for username so
- 2:35:01that's the laravel 10 block as for the
- 2:35:04password let's generate some password
- 2:35:06this one and I'm going to copy that and
- 2:35:10let's click create
- 2:35:12awesome now let's go into SSH terminal
- 2:35:17and we are going to edit dot en file
- 2:35:23okay let's scroll down below and here's
- 2:35:25our connection because we are developing
- 2:35:28through sale connection is actually
- 2:35:30MySQL we are going to change this into
- 2:35:33localhost
- 2:35:37um excuse me connection is the driver so
- 2:35:41that should be MySQL but the second
- 2:35:43MySQL which is DB host that needs to be
- 2:35:46changed into localhost Port stays the
- 2:35:50same the database uh well basically we
- 2:35:54created database this is going to be our
- 2:35:57database but because I have password
- 2:35:59already copied first I'm going to delete
- 2:36:02the password and paste the password here
- 2:36:05okay then let's get the username we
- 2:36:09should have it right here as the user
- 2:36:12and I'm gonna paste here and that is
- 2:36:16database let's copy that and paste
- 2:36:20oops right here
- 2:36:24awesome
- 2:36:26awesome let's move up and let's change
- 2:36:29up URL as well and that will be the
- 2:36:35codeholic.net let's specify https as
- 2:36:39well because we have now SSL certificate
- 2:36:41we can change the app name and let's
- 2:36:43call this
- 2:36:45laravel blog but we need to put this in
- 2:36:49double quotations because we used space
- 2:36:51inside the app name
- 2:36:54awesome we can switch this en into
- 2:36:57production but let's make everything
- 2:37:00working
- 2:37:02so save and we're going to execute now
- 2:37:07PHP Artisan migrate
- 2:37:11let's hit enter okay so the connection
- 2:37:13to the database was successfully done
- 2:37:15and migrations have been applied now if
- 2:37:18we check in the browser
- 2:37:20we should see okay what do we see
- 2:37:26post title is not in group by
- 2:37:30all right so that error basically
- 2:37:34happens due to mySQL configuration
- 2:37:37our sale our MySQL configuration which
- 2:37:41was running inside the sale was slightly
- 2:37:44different from the MySQL configuration
- 2:37:47which is on hostinger environment so we
- 2:37:50need to take care of this
- 2:37:53if we just read the error so that
- 2:37:55happens because we are selecting post
- 2:37:58title and we don't have that mentioned
- 2:38:01in the group by again we can change
- 2:38:03MySQL configuration in our hostinger I'm
- 2:38:06not sure if that's possible by the way
- 2:38:08but if that's possible one option is to
- 2:38:11change that second option is to slightly
- 2:38:13modify our query and add this is our
- 2:38:18select
- 2:38:19right here and add Group by post title
- 2:38:24and maybe a few other fields as well
- 2:38:27okay
- 2:38:29I can add post title on my local local
- 2:38:35environment into phpstorm but there
- 2:38:38might be other fields also which might
- 2:38:40be necessary to be added in the group by
- 2:38:42that's why I'm gonna do this directly on
- 2:38:47the server okay I'm going to edit this
- 2:38:49and do it right here we are selecting
- 2:38:52the following Fields like everything
- 2:38:55basically from Posts so if we go into
- 2:38:59phpmyadmin
- 2:39:01and click this enter phpmyadmin we will
- 2:39:04be connected into our deployed projects
- 2:39:08database
- 2:39:13here we can click on posts and see what
- 2:39:16fields we have right right here
- 2:39:20now let's go in our terminal SSH
- 2:39:24terminal and I'm going to edit
- 2:39:27into app
- 2:39:30controllers we need uppercase C
- 2:39:33TRL
- 2:39:35um excuse me up http
- 2:39:39controllers and the error coming from is
- 2:39:44host controller so let's open post
- 2:39:48controller okay we use the veeam so I'm
- 2:39:51going to hit I and let's actually do
- 2:39:54this because I'm doing this right now uh
- 2:39:58on the through the sh client simply
- 2:40:00because I don't know if it might throw
- 2:40:03an error on another field that's why I
- 2:40:06prefer to do this right here but I
- 2:40:08actually cannot read
- 2:40:10what's that
- 2:40:12the color is so blue I cannot read that
- 2:40:21okay can I change the background color
- 2:40:26yeah let's make it gray
- 2:40:29or like blackish something like this
- 2:40:33okay
- 2:40:36yeah that's I think better so we at
- 2:40:38least we can read everything maybe we
- 2:40:41can make it
- 2:40:42more dark
- 2:40:48yeah I think Ray was better so let's go
- 2:40:50in colors I'm going to change this into
- 2:40:53gray all right so here's my cursor
- 2:40:58here is my cursor so
- 2:41:03let's have a look
- 2:41:08this is the place I don't see the cursor
- 2:41:11so I should probably do this in PH store
- 2:41:15so here I have opened my project and
- 2:41:18let's open post controller
- 2:41:24scroll down below and the error
- 2:41:26basically coming from popular posts
- 2:41:29again we can check this in the browser
- 2:41:31yeah the popular post this is the
- 2:41:33problem so right here we are selecting
- 2:41:35everything from pose but we are only
- 2:41:38using Group by posts ID so I think we
- 2:41:43need to specify right here all the
- 2:41:46fields which which is part of the post
- 2:41:50table all the posts columns so let's
- 2:41:54click on structure and I'm gonna
- 2:41:57now let me have to open the database
- 2:42:00posts
- 2:42:02here we have all the columns and I'm
- 2:42:04gonna
- 2:42:04copy simply all of them
- 2:42:08like this
- 2:42:14here we go I'm going to paste all of
- 2:42:17them then use multi-cursor features and
- 2:42:21type hosts and dots whatever is the
- 2:42:24field and then we have comma now we have
- 2:42:29ID twice I'm going to remove once so now
- 2:42:31I'm grouping based on the all Fields
- 2:42:33because those are all fields which are
- 2:42:36used right here
- 2:42:37fingers crossed it should not be
- 2:42:40complaining it shouldn't complain
- 2:42:42anymore so let's comment this
- 2:42:46um weeks Group by issue let's comment
- 2:42:51everything
- 2:42:53now let's push that and now let's open
- 2:42:56Powershell let's
- 2:42:59quit from here
- 2:43:02don't save anything and quit from here
- 2:43:04and we are inside the project right so
- 2:43:08I'm gonna run git
- 2:43:10all to get the latest changes and here
- 2:43:13we see post controller was updated now
- 2:43:16if I check in my browser reload the page
- 2:43:20we don't see this error but we see the
- 2:43:23same error on recommended posts so let's
- 2:43:26open again post controller
- 2:43:29let's grab those maybe the entire group
- 2:43:33by
- 2:43:34scroll down below and here we have that
- 2:43:37we're selecting everything from Pro
- 2:43:39posts byte grouping only post ID
- 2:43:42the entire group by can be replaced with
- 2:43:44this one format code to have something
- 2:43:47similar
- 2:43:48um
- 2:43:49Group by categories ID
- 2:43:54select categories I think it will
- 2:43:56complain
- 2:43:58right here as well
- 2:44:01yeah it will complain but I want to see
- 2:44:03that okay fixed Group by issue for
- 2:44:07we fixed that for recommended posts
- 2:44:10here we go
- 2:44:12so let's commit
- 2:44:16push
- 2:44:18open Powershell run gitpool that was
- 2:44:21updated reload in the browser
- 2:44:25and we see yeah I was right we see now
- 2:44:28on categories so on categories let's
- 2:44:31scroll down below how many fields do we
- 2:44:33have inside categories let's grab all
- 2:44:36those fields they are not that many
- 2:44:41and here
- 2:44:43paste all of them
- 2:44:47categories dot column name
- 2:44:52here we go fix Group by issue for
- 2:44:56categories
- 2:44:58it should the the commitment should be
- 2:45:00more descriptive to be honest so I just
- 2:45:02I'm just trying to hurry up a little bit
- 2:45:04and to waste your time but the ideal
- 2:45:08comment message should be
- 2:45:11fix Group by issue
- 2:45:15for
- 2:45:17in selecting
- 2:45:20categories or home page
- 2:45:23like this and the same type of comment
- 2:45:26message you should use for the other two
- 2:45:29things like right here and right here
- 2:45:32now I'm going to comment this
- 2:45:35I'm going to push that
- 2:45:38open Powershell run git pull that was
- 2:45:42updated reloading the browser
- 2:45:46okay we have another error the same type
- 2:45:50of error coming from App layout
- 2:45:56up layout
- 2:45:58okay now it's getting
- 2:46:00um
- 2:46:01awkward
- 2:46:03let's fix that but now I'm thinking if
- 2:46:06it is possible to change MySQL
- 2:46:08configuration options
- 2:46:12typically on management
- 2:46:14I think we we don't have that
- 2:46:16possibility so that's a option which is
- 2:46:18called Full Group by full Group by
- 2:46:21option
- 2:46:22and that is activated as it looks like
- 2:46:25so now let's go in up layout
- 2:46:30up
- 2:46:32layout
- 2:46:36and what do we do
- 2:46:40we select categories title but Group by
- 2:46:42only ID we Select Title slug in others
- 2:46:47but we Group by ID
- 2:46:49if we have a look in the error we need
- 2:46:52to include title and slack so I'm going
- 2:46:55to get these two columns
- 2:46:58and paste them right here
- 2:47:01now let's give it a comment message fix
- 2:47:04Group by issue by selecting
- 2:47:07in
- 2:47:09app layout
- 2:47:11let's do like this
- 2:47:13comment and push
- 2:47:16now let's again run git pull that was
- 2:47:18updated to have another error
- 2:47:22we do have something
- 2:47:24okay let's have a look because we don't
- 2:47:26have data there's an error that error is
- 2:47:29coming from up modules so in the
- 2:47:32Constructor of post item
- 2:47:34right here it expects to pass post
- 2:47:37button now it's actually given
- 2:47:40and from where does this happen
- 2:47:44let's check
- 2:47:46how is it possible that post item is
- 2:47:49triggered
- 2:47:54post item is rendered but there is
- 2:47:57actually no post to it
- 2:48:00that's interesting so where does this
- 2:48:03error is coming from let's check this
- 2:48:05coming from home blade
- 2:48:07here we go
- 2:48:09obviously latest post does not exist all
- 2:48:13right let's open home.play generally
- 2:48:16from my experience when you build your
- 2:48:19application everything works fine
- 2:48:21everything is smooth and you're happy
- 2:48:23with that as soon as you tell your
- 2:48:25friend hey I finished working on on the
- 2:48:27application can you clone that and have
- 2:48:29a look and when the friend clones that
- 2:48:32and runs on an empty data then problems
- 2:48:35really happen so it's recommended always
- 2:48:37to test your application before you
- 2:48:40deploy it on production or give tell it
- 2:48:43to your friend test your application on
- 2:48:46empty data on a fresh new installation
- 2:48:48that happened a lot to me in the past
- 2:48:52and it happened right now as well so
- 2:48:54we're going to check simply if the
- 2:48:57latest post exists we are going to
- 2:49:00render that component
- 2:49:05all right
- 2:49:06again
- 2:49:07now let's give it a comment message
- 2:49:10add security check
- 2:49:14if latest post exists before rendering
- 2:49:23okay
- 2:49:25now we push that
- 2:49:28we pull that
- 2:49:30and what's the next error
- 2:49:32the next error is something which
- 2:49:36um I really expected so this is the only
- 2:49:38error I actually expected so far so that
- 2:49:41happens because we don't have that
- 2:49:44manifest we don't have assets actual
- 2:49:46assets if we are doing this on a
- 2:49:48development environment we can run npm
- 2:49:51run Dev but we if we are doing this on
- 2:49:53production we need to run npm run build
- 2:49:56so this can be done in two ways
- 2:49:59first is to run that on the server right
- 2:50:03here and we can run npm run build but
- 2:50:06that's not going to work because npm
- 2:50:08comment is not available on hostinger's
- 2:50:11shared hosting if you don't believe me
- 2:50:12you can hit right here and you you will
- 2:50:14see that
- 2:50:15now we are going to do this in a
- 2:50:18slightly different way so we are now run
- 2:50:20npm run build well actually we need to
- 2:50:24First go inside the container
- 2:50:28a window being sailed up
- 2:50:34let's open a new terminal vendor bin
- 2:50:38sale Bash
- 2:50:40we are in the container and now let's
- 2:50:42run npm run build
- 2:50:47okay
- 2:50:48that will create the following files
- 2:50:52build manifest Json build assets up CSS
- 2:50:55and build assets app.js but
- 2:50:59those files are actually ignored we
- 2:51:02don't see these in uncommitted changes
- 2:51:05if we check git ignore we are going to
- 2:51:08see that
- 2:51:10public build so everything from the
- 2:51:12public build is ignored and that's
- 2:51:15actually good practice because they are
- 2:51:16generated files and when you deploy that
- 2:51:18somewhere you should run npm run build
- 2:51:22right there but because our environment
- 2:51:24doesn't support npm at the moment so we
- 2:51:27can remove that and that's also fine I
- 2:51:30have been using this approach for many
- 2:51:32years previously
- 2:51:33the only thing that might happen
- 2:51:37because you are commenting build files
- 2:51:40is that if you are working with a team
- 2:51:42you might have conflicts when you build
- 2:51:46something and your colleague will build
- 2:51:48something there will be conflict in
- 2:51:50app.js in app CSS but
- 2:51:52to fix those errors are very easy you
- 2:51:55just need to
- 2:51:57take either your version or your
- 2:52:00colleague's version and then run npm run
- 2:52:03build once again because
- 2:52:05it's going to be finally generated from
- 2:52:07your source files
- 2:52:08all right so now in the uncommitted
- 2:52:11changes we see those files so we're
- 2:52:13gonna commit that
- 2:52:15add
- 2:52:16build folder
- 2:52:19let's Commit This
- 2:52:23let's push this
- 2:52:26let's pull it
- 2:52:28on our server
- 2:52:30and let's check in the browser what is
- 2:52:33the next error okay we don't have next
- 2:52:35error anymore which is awesome if we
- 2:52:39check right now database and if we check
- 2:52:41specifically users
- 2:52:44I think we don't have any users so let's
- 2:52:46try to create one I'm going to check
- 2:52:49what code I have inside database Cedar
- 2:52:52here we create the user and we assign
- 2:52:55role to that that's perfect now let's
- 2:52:58open a search terminal and execute PHP
- 2:53:00artisan
- 2:53:02and DB colon seat let's hit the enter
- 2:53:05setting database perfect that was
- 2:53:08finished it will reload the users table
- 2:53:10we see there is admin user now I can
- 2:53:14access to
- 2:53:16admin
- 2:53:18let's check we probably have some errors
- 2:53:21in admin as well what's the password
- 2:53:25is the password
- 2:53:27remember me click sign in
- 2:53:30let's check it
- 2:53:32okay so dashboard is good let's click on
- 2:53:35categories that's good let's click on
- 2:53:37post that's good text switches so it
- 2:53:40looks like everything is working so I'm
- 2:53:42going to create now test category
- 2:53:43JavaScript
- 2:53:46let's click on create
- 2:53:49let's create
- 2:53:51test post
- 2:53:54let's make it active
- 2:53:57to display it on the website
- 2:54:00body okay let's give it some test
- 2:54:03create that was created and
- 2:54:08and let's actually assign it a category
- 2:54:12of
- 2:54:14JavaScript and I'm going to also test
- 2:54:17what's going to be the
- 2:54:20if image upload successfully works so
- 2:54:23I'm going to choose one image right here
- 2:54:26it's floating upload completed
- 2:54:30click save changes that was saved if I
- 2:54:33click on posts I see thumbnail right
- 2:54:35here and that's awesome I click
- 2:54:38open the new tab and we see this new
- 2:54:40post
- 2:54:41okay so it looks like everything is
- 2:54:44working we have this in popular posts we
- 2:54:46have this uh here as well we have this
- 2:54:49tag category here we have the number of
- 2:54:53minutes in one word we click it opens
- 2:54:57the inner page and here we have another
- 2:54:59problem on inside there that comes from
- 2:55:02sidebar View and blade component sidebar
- 2:55:07let's check now
- 2:55:08sidebar
- 2:55:13this is the select we are selecting
- 2:55:15categories title and slug but we are
- 2:55:18only group buying using ID so let's use
- 2:55:21title and slug as well
- 2:55:24now I'm going to choose comment message
- 2:55:27fix Group by issue in
- 2:55:31sidebar
- 2:55:33click commit
- 2:55:37now let's push that
- 2:55:40foreign
- 2:55:44pulled actually git pull
- 2:55:48and now reload
- 2:55:51okay here we go the sidebar however
- 2:55:56does not
- 2:55:58is not on the right side
- 2:56:01which is kind of strange if we check
- 2:56:04this on localhost
- 2:56:10okay
- 2:56:12um recently I had a Docker problem so I
- 2:56:15locally deleted everything
- 2:56:19in my local installation
- 2:56:22that's why I don't have post table
- 2:56:27okay I run migrations locally and
- 2:56:29created the exact same post locally and
- 2:56:32we have the same problem locally as well
- 2:56:33so we probably messed up something if we
- 2:56:36click we're going to open view dot blade
- 2:56:39PHP and we are gonna have a look
- 2:56:43this is the article
- 2:56:46we have a sidebar
- 2:56:48so the layout
- 2:56:51doesn't have display Flex
- 2:56:55okay let's search for what is up dot
- 2:56:59blade dot PHP yeah we I think we remove
- 2:57:04display Flex from this container and
- 2:57:07that's why we have this problem no big
- 2:57:09deal I think we need to wrap this in a
- 2:57:12div and give this div
- 2:57:15Flex
- 2:57:17if I save these we need to obviously
- 2:57:19have run npm run Dev at the moment and
- 2:57:23then we're going to run npm run build
- 2:57:26reload the page
- 2:57:28and here we go so we see all categories
- 2:57:30on the right side clicking on JavaScript
- 2:57:32will filter that properly
- 2:57:36okay awesome and if we create text
- 2:57:38widget obviously it's going to appear
- 2:57:40right here now let's run npm run build
- 2:57:44because we need latest version of CSS we
- 2:57:47made some changes here
- 2:57:49it might be updated or it might not even
- 2:57:52be updated
- 2:57:54here we see that it is actually updated
- 2:57:55up CSS so we are going to fix and
- 2:57:59comment now all of them
- 2:58:02here we go
- 2:58:05okay
- 2:58:06fix sidebar CSS issue
- 2:58:11we commit that
- 2:58:13we push that
- 2:58:17we pull that on the server
- 2:58:20and we open
- 2:58:24we open the production environment we
- 2:58:27load that and we see sidebar on the
- 2:58:29right side
- 2:58:31if we just search for something like
- 2:58:34test
- 2:58:36it doesn't find the eight fines right
- 2:58:39there if we find Test 2
- 2:58:42it doesn't find there so search actually
- 2:58:45also works perfectly
- 2:58:48about us page is it at the moment empty
- 2:58:54okay one last thing which I'm going to
- 2:58:56mention is
- 2:58:58login and registration especially
- 2:59:00registration and password reset so we
- 2:59:03don't have proper SMTP credentials so if
- 2:59:08we open Dot en file and if we scroll
- 2:59:12down below
- 2:59:15here we see that the mailer is an SMTP
- 2:59:18and host is male pit so that was good
- 2:59:21for local development but on production
- 2:59:23this is not going to work so you have to
- 2:59:27use some kind of production ready SMTP
- 2:59:29for that such as Gmail or maybe Office
- 2:59:33365
- 2:59:35maybe mail gun you can use mail gun as
- 2:59:38well and few others there are a few
- 2:59:40others as well but the main idea is that
- 2:59:43you need some kind of real SMTP to
- 2:59:47validate
- 2:59:49to send emails from your domain like in
- 2:59:52my case it's going to be probably no
- 2:59:54reply at the codeholic.com there are
- 2:59:57many providers you just need to figure
- 2:59:59out which one you want one of them is
- 3:00:01Gmail second is AWS SES and there are
- 3:00:05tons of others
- 3:00:07all right so the hostinger actually also
- 3:00:11gives you possibility to create email so
- 3:00:14if we
- 3:00:16click on emails right here from our
- 3:00:19domain like I already have many emails
- 3:00:22if we check the domain we just took
- 3:00:27where is that
- 3:00:29uh nicole.net we haven't set up any kind
- 3:00:33of email we can click manage right here
- 3:00:35and take a domain but be aware that it
- 3:00:41is not intended for massive email
- 3:00:44sending
- 3:00:45if you don't expect to have like high
- 3:00:48load on your website and a lot of
- 3:00:49registrations I think you can use that
- 3:00:53it's a good no problem if you're going
- 3:00:55to have uh like a lot of registrations
- 3:00:58this is not intended for that and also
- 3:01:00don't use it for sending emails to
- 3:01:04non-existing addresses because that's
- 3:01:07gonna probably suspend your email
- 3:01:09account
- 3:01:10which is going to be not really good
- 3:01:13all right so we deployed our pro project
- 3:01:15on production environment with custom
- 3:01:18domain Excel certificate MySQL and
- 3:01:21everything works perfectly alright my
- 3:01:23friends this is for this video and I
- 3:01:25appreciate your time and thanks for
- 3:01:27watching if you like the video please
- 3:01:28leave Thumbs Up And subscribe to the
- 3:01:31channel if you are not yet because I
- 3:01:32plan much more content on variable and
- 3:01:35PHP if you like this video maybe you
- 3:01:37want to check another video in which I
- 3:01:39talk about 10 PHP projects which you
- 3:01:42should definitely build as a PHP
- 3:01:44developer and that can definitely
- 3:01:46improve your PHP skills you can find
- 3:01:48this video right here thanks for
- 3:01:50watching and I will see you in the next
- 3:01:51one
About this transcript
This page contains the full transcript of Laravel Blog: Comments, Global Search, Deployment | Part 3 by The Codeholic, generated from the public captions YouTube serves with the video. The transcript has 20,803 words across 3,662 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.