Laravel Blog: Roles & Permissions, Likes & Dislikes, View Count | Part 2 — Transcript
Full transcript
- 0:00I'm building blog websites with admin
- 0:02panel in lateral 10. if you haven't
- 0:04watched the first part click right here
- 0:06in this video we are going to add user
- 0:08registration login email verification
- 0:09password reset with alarable Breeze we
- 0:12will install spotty permissions package
- 0:14and create user and admin roles and
- 0:16restrict access to admin panel we will
- 0:18Implement post likes and dislikes using
- 0:21laravel Livewire we will count number of
- 0:24views on post and then in admin panel we
- 0:26will output analytics such as number of
- 0:28views number of likes or dislikes for
- 0:30each post we will Implement brand new
- 0:32homepage with four main sections latest
- 0:35article the most popular three articles
- 0:38based on likes recommended articles
- 0:41based on user likes history if the user
- 0:43is authorized if the user is guessed
- 0:45then we're going to show recommended
- 0:47articles based on number of views we're
- 0:49going to show top categories by their
- 0:51latest posts we will add search field
- 0:54for posts and categories in admin panel
- 0:56we're going to fix and improve multiple
- 0:58minor things
- 1:04comments on the post s Implement Global
- 1:07search on the website and maybe deploy a
- 1:11project on production environment with
- 1:13custom domain
- 1:16don't tell anyone and maybe you don't
- 1:19want to subscribe because you're
- 1:21constantly checking my YouTube channel
- 1:23if I uploaded any new video alright no
- 1:26further Ado let's jump into the video
- 1:28now let's start working on user
- 1:30registration and logging and for this
- 1:33we're going to use laravel Breeze uh you
- 1:36can have a look at the lateral Breeze
- 1:37documentation is pretty straightforward
- 1:39to install that
- 1:40I'm going to have the documentation
- 1:42always opened and even though I know
- 1:45what comments I should type it's always
- 1:47you're going to always make much less
- 1:50mistakes when you actually copy these
- 1:51and like don't have a typo when you're
- 1:55typing okay so I'm gonna
- 1:57um actually first we're gonna start the
- 2:00server vendor being sale up then we're
- 2:06gonna go inside the container
- 2:08Bender actually
- 2:11I'm going to exit this stop that and I'm
- 2:15going to start my application in a
- 2:17detached mode
- 2:19so vendor Bean sale app testing
- 2:23okay containers have been started now
- 2:26let's access the container when you're
- 2:27being
- 2:28sale Bash
- 2:31and now from inside that container we're
- 2:34going to execute composer require
- 2:35lateral Breeze Dev
- 2:37okay that was installed then we're gonna
- 2:39execute
- 2:41uh PHP
- 2:44artisan
- 2:46Breeze column install
- 2:49that will ask whether which stack we
- 2:51want to install so we are not using view
- 2:55or reactor API in this case so I'm going
- 2:57to provide the zero right here whether
- 2:59we want to install Dark mode support I'm
- 3:02going to provide no right here if we
- 3:05want tests no right here as well and we
- 3:08have an error and that error was
- 3:10expected because lateral Breeze is
- 3:13intended to be installed as a very first
- 3:15thing after you create your level
- 3:17application so it expects welcome blade
- 3:21PHP to exist on the reviews folder which
- 3:24doesn't exist so that's why we have this
- 3:26problem now I'm going to open
- 3:29resources views and simply I'm going to
- 3:33copy and paste homeblade and call this
- 3:35welcome blade PHP so I'm not going to
- 3:39use this welcome blade but I am simply
- 3:42creating this because lateral Breeze
- 3:43needs that and then later when lateral
- 3:46Breeze installs I'm going to adjust the
- 3:48content and create and maybe modify a
- 3:51few views and so on okay before we
- 3:54execute lateral Breeze one like a
- 3:57disclaimer lateral Breeze will modify
- 3:59your views and layouts and few other
- 4:01things so make sure you have everything
- 4:04picked up like for example and my
- 4:07recommended way to backup everything is
- 4:09using git so use version control system
- 4:12and comment everything before you run
- 4:15lateral Breeze in this case because as I
- 4:17mentioned It's Gonna Change many things
- 4:19in your project okay I have everything
- 4:21commented I'm Not Afraid about losing
- 4:23anything so I'm going to execute please
- 4:26insta zero no and no
- 4:30now let's wait few seconds Breeze was
- 4:33installed then it run npm install and
- 4:35npm run the npm Run build we're going to
- 4:38execute npm run Dev
- 4:40by ourselves and now let's have a look
- 4:44so here's our application and let's
- 4:47access to the main page and we have
- 4:50undefined variable posts and that comes
- 4:53from welcome blade okay welcome blade
- 4:55was used by laravel Breeze automatically
- 4:57now let's open web.php which is our main
- 5:01roads file
- 5:03and right here everything was modified
- 5:05by lateral priests so this like a CN
- 5:09color line indicates that I have changes
- 5:12that uh changes come from version
- 5:14control system so basically if I click
- 5:17this I see what was my previous version
- 5:19so I'm going to copy this part and at
- 5:22the very very bottom I'm going to put
- 5:25that so my roads and also at the top
- 5:28these Imports have been changed I'm
- 5:30going to copy this and I need profile
- 5:33controller but I need my post controller
- 5:36inside controller as well so now in my
- 5:39web HP I have uh like modifications
- 5:42bilateral Breeze as well as my previous
- 5:44rows what I had before so small hint
- 5:49right here don't put these above because
- 5:53this is a very very generic route so it
- 5:57is matching all the everything
- 6:00if the previous rows didn't match so
- 6:03whenever you try to access a dashboard
- 6:05or profile or any other robe declared
- 6:07before this will match and it will it
- 6:11will use that
- 6:13so this needs to be at the very bottom
- 6:15if you don't believe me you can put this
- 6:17at the very top and you can just try to
- 6:19access like other pages and you will see
- 6:21an error okay I'm going to save these
- 6:24and let's modify a few things I don't
- 6:26need this uh welcome because I am using
- 6:30the post controller index and let's save
- 6:33this and have a look so we have this
- 6:35error that comes from navigation blade
- 6:38navigation blade is something also
- 6:41introduced by Laurel Breeze and let's go
- 6:44in The Roots resources Fields views
- 6:49layouts and right here we have this up
- 6:51plate and right here like almost every
- 6:54line was changed by lateral Breeze
- 6:56I want to recover my previous layout but
- 6:59I need few things from here like for
- 7:02example
- 7:03white scripts CSS and javascripts which
- 7:07I want to put in my layout and maybe
- 7:11also later we can move our header into
- 7:14layouts navigation and so on so I'm
- 7:17going to copy everything and create new
- 7:20temporary file like scratch file and I'm
- 7:22going to paste everything right here and
- 7:25I'm going to revert everything using
- 7:27version control system if you had up
- 7:29late PHP picked up then you can easily
- 7:32revert that so I'm gonna select
- 7:34everything and type a control alt and Z
- 7:37on my keyboard and it's gonna
- 7:40that's going to revert everything inside
- 7:42this file I save this rule of the page
- 7:45and we have another problem and that
- 7:47comes from the layout again but that
- 7:50happens because the component was
- 7:53changed the layout component if we go in
- 7:55the app view app layout right here a few
- 7:59things have been completely removed like
- 8:01the Constructor was removed so I'm going
- 8:04to revert that so I need this and also
- 8:07Imports have been removed I'm going to
- 8:09revert this as well so now I save this
- 8:12and reload the page Nic application
- 8:14working right so I can navigate between
- 8:17pages and that was completely fine
- 8:20however if I try to access like login
- 8:23for example we don't have styles at all
- 8:26so how we're going to do that now let's
- 8:29open the scritch file and I'm going to
- 8:31copy these white tag and let's open up
- 8:36blade scroll up and I'm going to put
- 8:39this uh before closing headtech
- 8:43like this
- 8:45this actually these resources app.js if
- 8:48we have a look
- 8:49uh let's go under resources JS and
- 8:53app.js this uses Alpine this Imports
- 8:56Alpine so we have already Alpine and we
- 8:59can remove this JavaScript from CDN if
- 9:02we open these app CSS this uses Talon
- 9:05CSS so we can completely remove these
- 9:08Talon CSS from CDN which is fine great
- 9:12now if we save this and reload we see
- 9:16our Styles in JavaScript is completely
- 9:18broken
- 9:20and that as I figured out is kind of bag
- 9:23of laravel sale in white combination of
- 9:28together if I try to access any URL
- 9:30these styles are not there if I open
- 9:32developer tools
- 9:33and expand that reload we see that error
- 9:38address is invalid now let's go in the
- 9:41white config it is in the root of the
- 9:46project and right here at the very top
- 9:48we're going to add server we're going to
- 9:51provide HMR
- 9:53and we're going to provide host to be
- 9:56localhost
- 9:58you should provide right here
- 10:00whatever is the domain your local domain
- 10:04okay so I'm going to save that
- 10:07and now if I reload these it's going to
- 10:10take a few seconds but now we see that
- 10:13the styles are big
- 10:15and we can navigate and we see
- 10:18everything is okay and we can also try
- 10:21to access login page and styles are
- 10:24there
- 10:25now this login page doesn't have header
- 10:27and footer which is something I want my
- 10:29blog to have my the login page of my
- 10:33blog to have also
- 10:35um the forward password as well as the
- 10:38registration all of them needs to have
- 10:40this header and footer
- 10:42those files are defined by lateral
- 10:45Breeze and they are available under
- 10:47resources views all folder and if we
- 10:51have a look all of those files have the
- 10:54layouts the main component they are
- 10:56using is the guest layout
- 10:59and if we open now guest layout
- 11:02there are obviously no header in footer
- 11:05and this is the guest layout and this is
- 11:07something I want to modify so that
- 11:11header and footer to be there so this is
- 11:14a layout but I'm going to actually
- 11:15change this slightly I'm going to remove
- 11:18this body and head completely let's
- 11:21remove this HTML as well and this right
- 11:26now is a guest layout but I want this to
- 11:31extend X up layout
- 11:34okay now let's format the code and now
- 11:39whenever the login form is rendered
- 11:41here's the login form it has
- 11:44this HTML included which on its own is
- 11:49extending the app layout okay we
- 11:52probably we probably don't need
- 11:54everything maybe we don't need logo we
- 11:56can remove that
- 11:57mean h screen maybe this is something we
- 12:00can remove as well
- 12:03and that's more like it there is
- 12:05probably some kind of padding padding
- 12:07top and we can remove that PG gray maybe
- 12:11we can remove it
- 12:13save
- 12:15okay that's much better and I want this
- 12:18form to be in the center
- 12:20so we have this justify Center but we
- 12:24have this uh under above small screens
- 12:27which we don't need
- 12:29we wanted this to be always in the
- 12:31center
- 12:32and we have with full
- 12:37maybe we can remove this with full and
- 12:40Max with medium margin top padding
- 12:46let's remove all that and have a look
- 12:50okay we need paddings
- 12:52we need padding
- 12:55how to put this in the center let's
- 12:58remove this w
- 12:59okay now let's inspect this and have a
- 13:01look so this is the
- 13:04this is the form
- 13:07this is the container okay the container
- 13:10which
- 13:12I see so the container comes from the
- 13:14app layout
- 13:16and if we open up layout and find where
- 13:20the main content is injected right here
- 13:23and if we just provide right here
- 13:25justify Center Maybe
- 13:29justify justify Center then the full
- 13:33form will go in the center or maybe we
- 13:36can undo these
- 13:38and open
- 13:41this guest blade
- 13:43and give this one w
- 13:47ool always
- 13:49and then this one already has justify
- 13:52Center okay I think that's better like
- 13:55making a change in the up blade is kind
- 13:57of okay but because the upload is used
- 14:00on other Pages as well it's not 100
- 14:03correct to make change right here
- 14:05instead making changes in the guest
- 14:08blade will be much more safe we are sure
- 14:11that we aren't going to break home or
- 14:14any other pages
- 14:15okay that's perfect now every out page
- 14:19is in the layout
- 14:21I don't actually like the width of the
- 14:24forms so maybe we can do something Max
- 14:28with
- 14:29instead of MD maybe we can provide LG
- 14:36we need to wait
- 14:41uh okay
- 14:44it didn't work for some reason
- 14:49that has
- 14:51Max with LG
- 14:59let's provide Excel
- 15:06okay it has Max width but maybe we want
- 15:10to Define like a width or Min width as
- 15:12well or maybe this is even fine like not
- 15:15big deal so we have uh enough width for
- 15:19each individual field right
- 15:24I cannot I access login
- 15:27here I have the login
- 15:29okay so now let's try to log in and
- 15:32let's take here also putting the login
- 15:36and registration buttons in my profile
- 15:38buttons in the navigation as well okay
- 15:41if I try to log in right now I'm logged
- 15:44in this redirects me to the dashboard
- 15:47which is uh something we don't we don't
- 15:51have at the moment we don't have
- 15:52dashboard so probably we don't need that
- 15:56at the moment
- 15:58so for now I'm gonna simply remove this
- 16:02redirect to dashboard and that was
- 16:05basically modified in the road service
- 16:08provider right here
- 16:10that home was changed into dashboard and
- 16:13I went actually uh revert this into home
- 16:17again
- 16:19and now I cannot log I cannot log out
- 16:24because I don't have logout link
- 16:26okay let's actually take care of the
- 16:29putting proper links in the navigation
- 16:31right let's open
- 16:35navigation blade PHP and let's have a
- 16:39look we have couple of links primer
- 16:41navigation menu uh we have this
- 16:44navigation links which goes to dashboard
- 16:48and activates that right here it
- 16:51displays the user information who is
- 16:54actually authorized at the moment and I
- 16:56think that drop down is something we
- 16:58might need
- 17:01and we also need
- 17:06we also need logout
- 17:11like we have this here okay if we pay
- 17:14attention this is a responsive settings
- 17:16option so that is visible for mobile
- 17:20that is visible for mobile and the above
- 17:23one is visible for
- 17:28um for a desktop right but where is the
- 17:32actual login
- 17:36and sign up
- 17:38where's that
- 17:40here's the log out let's search for a
- 17:43login
- 17:45we don't have this here
- 17:47we don't have probably this in the guest
- 17:49layout probably it was in the
- 17:53up blade which
- 17:56should be a scratch file now here it is
- 18:00so I have the scratch file
- 18:02and there was a header
- 18:06okay that was coming probably from there
- 18:09anyway let's
- 18:10go in our up blade
- 18:14and we have the following navigation
- 18:17links
- 18:18and let me actually take one of the
- 18:21links
- 18:22and put them like this
- 18:26okay that should be login
- 18:29we're going to adjust CSS
- 18:31a little bit later this is register
- 18:35let's provide proper tests uh texts
- 18:38register
- 18:40and this is
- 18:43logging so we save and we see login and
- 18:46register however they should not be
- 18:49visible if the user is already
- 18:52authenticated because right now it
- 18:54redirects us to home which is also not
- 18:56correct and if we open this
- 18:58road service provider
- 19:02wrote a service provider and if we
- 19:05simply change this home into slash that
- 19:08will be more accurate clicking redirects
- 19:11us to home page we need to hide login
- 19:14load login and registration with user is
- 19:17already authorized
- 19:19so let's use auth
- 19:25a directive
- 19:29and
- 19:30alph
- 19:35that should be not Alf to be honest so
- 19:40let's do like this if the user is
- 19:42authorized we're going to display the my
- 19:44profile section then we're going to have
- 19:46else
- 19:48and we're going to display this so if I
- 19:50save now we don't see a login and
- 19:52registration which is perfect now if we
- 19:56open navigation blade here we have this
- 19:59settings drop down which is again for
- 20:03desktop the second one is for Mobile in
- 20:07this case let's make it simple we
- 20:09haven't done any changes regarding
- 20:12making our blog responsive so simply I'm
- 20:15going to take this part
- 20:18and go in the upblade and paste this
- 20:21right here I'm doing this only for
- 20:23desktop at the moment let's remove this
- 20:25hidden
- 20:26and let's give it display Flex let's
- 20:30save it have a look okay we have this
- 20:33drop down uh the profile is available
- 20:38and the logout will probably work
- 20:40perfect so now we have login and
- 20:43register I click on login click on
- 20:45register both working let's log in again
- 20:48and we have this my profile these styles
- 20:50of this my profile of course is not nice
- 20:53it should be probably in the styles of
- 20:55this so let's give it some small
- 21:01let's take the following classes and
- 21:03maybe
- 21:04modify this part
- 21:08yeah there are a lot of classes
- 21:10so let's paste this and have a look
- 21:15um okay let's give it
- 21:18legs
- 21:21paint items Center
- 21:26okay
- 21:28that's good
- 21:29let's leave it as it is right now
- 21:33or maybe we can put this navigation on
- 21:36the left side and these on the right
- 21:38side so what I'm going to do
- 21:41is we have this widthful and container
- 21:45and it has flex and it has Flex column
- 21:49as well but those are for mobile okay on
- 21:52above small screens we have Flex row
- 21:56item Center we don't want justify Center
- 21:59let's give it a justify between
- 22:04and now let's put those links in a div
- 22:11and
- 22:12those will be in another div
- 22:17like this
- 22:19now if I say that
- 22:21let's collapse this part if I say that
- 22:24this is how it looks like okay so we
- 22:27have this main navigation on the left
- 22:29side we have this user related
- 22:32navigation on the right side if I log
- 22:35out I see login and registration right
- 22:37here okay that's I think
- 22:40that looks much better okay now we have
- 22:43the differentiation between the normal
- 22:45navigation and the user related
- 22:47navigations in ideal case this register
- 22:49button even needs to be probably kind of
- 22:52Blue by default so why don't we make
- 22:55this blue
- 22:59and let's give it also text White
- 23:02like this so this is already like it's
- 23:06try it's takes our attention and we want
- 23:09to click that in register uh immediately
- 23:12right
- 23:14okay so this is what we're we're doing
- 23:18right now
- 23:20now let's have a look all the files that
- 23:22have been modified right now and I'm
- 23:24gonna use git for this so road service
- 23:27provider was changed into slash that's
- 23:29fine up CSS app Javascript was modifying
- 23:31that's fine Apple blade was modifying
- 23:34modified that's also fine now I don't
- 23:37want to these styles to be inside the
- 23:40layout so I will open that layout take
- 23:44this out from here and open this up CSS
- 23:48and paste them here okay so I want them
- 23:52to be inside CSS not inside HTML let's
- 23:55continue this is the app play that was
- 23:57modified we have this welcome blade
- 24:00which we don't need at all so that was
- 24:03created because of lateral breeze so I
- 24:06can delete this welcome blade and
- 24:08nothing will be broken
- 24:10I hope so if something was broken we're
- 24:13gonna of course fix and we we need to
- 24:15fix that okay then inside the web uh
- 24:19webphp those are the modifications that
- 24:21have been made that's fine we have the
- 24:24dashboard wrote
- 24:27um which
- 24:29which we probably need
- 24:31maybe we will need this later but at the
- 24:35moment
- 24:36it is not necessary
- 24:40okay let's leave this right now let's
- 24:43leave it it doesn't hurt then we have
- 24:45this composer Json which is the um which
- 24:48will have just lateral Breeze the white
- 24:50config and down below all the new files
- 24:54that have been generated by lateral
- 24:56Breeze like the controllers and we're
- 24:59going to have request files and
- 25:02components as well as the views
- 25:04and we also have some profile partials
- 25:07and layouts and test files okay
- 25:12so I don't see anything suspicious right
- 25:15here so I will be happy to comment those
- 25:18changes and make it available just
- 25:21um I'm gonna have a look at the final
- 25:23check we need to register and we need to
- 25:27also verify our email address if that is
- 25:31something which comes with a lateral
- 25:34Breeze if we open user PHP
- 25:38um
- 25:38okay
- 25:40if you open user PHP we must Implement
- 25:43an interface must verify
- 25:48Master verify email okay if we don't
- 25:51implement this interface whenever user
- 25:53registers his email is automatically
- 25:55verified and he will be able she will be
- 25:59able to access the system without email
- 26:01verification this is something uh which
- 26:04should be avoided and that's why I'm
- 26:08going to implement must verify email and
- 26:13now if I try to
- 26:15try to register let's use a seven-time
- 26:19email mailriate example.com let's
- 26:22provide some secure password
- 26:26so in it okay let's hit the enter
- 26:29okay it looks like we are actually
- 26:32authorized and we're in the system
- 26:37but
- 26:40okay
- 26:43this is this is tricky if we try to
- 26:46access dashboard right now
- 26:49let's have a look
- 26:50look at this thanks for signing up
- 26:52before getting started could you verify
- 26:55your email address by clicking on the
- 26:57link we just emailed to you if you
- 26:59didn't receive blah blah blah okay so we
- 27:02are actually authorized but we are not
- 27:04verified that's why
- 27:07the I'm going to close every tab
- 27:10and now I'm going to open Weber PHP uh
- 27:14because we are using verified middleware
- 27:16right here uh we aren't able to access
- 27:19the dashboard
- 27:20but we are able to access profile
- 27:24and we are able to update our password
- 27:26or delete the account and we are able to
- 27:29access the home page we are able to do
- 27:31basically everything
- 27:33which is
- 27:35kind of correct we don't do anything
- 27:38suspicious that requires email
- 27:41verification at this stage
- 27:43but if we are now for example do some
- 27:46action such as maybe leaving a comment
- 27:49on the article or upvoting an article we
- 27:53need to verify we need to be verified to
- 27:56do this type of action okay
- 27:59that's why maybe we can leave this as
- 28:02this right now but we should have
- 28:05received email verification which we
- 28:07need to verify I'm going to open now
- 28:10test email client
- 28:13which will be defined as a service in
- 28:16the docker composer yml and right here
- 28:19we see this mailpeat and which has which
- 28:23is exposed on the following Port
- 28:268025 so if we open our browser and
- 28:30access localhost port 8025
- 28:35here we are going to see the client
- 28:37which is a local client for every kind
- 28:40of email and as we see nine minutes ago
- 28:43we received the following email and this
- 28:47is the email when we click on these we
- 28:49can verify in this is why I love working
- 28:52with Docker in general because you can
- 28:55set up all your services in a single
- 28:57Docker compose yml and test email
- 29:00ascending and database and everything in
- 29:04a single Docker compost yml and you
- 29:06don't need to worry about setting up all
- 29:09your clients and environments right
- 29:12hey okay if we have a look again the
- 29:15problem or the problem but the fact is
- 29:18that we our email is not verified now I
- 29:21click on this verify email address you
- 29:23are logged in I'm on the dashboard now I
- 29:25am verified and from now on I'm going to
- 29:27use this client whether I want to
- 29:29recover password or producer is not the
- 29:33user I can use this client and I will
- 29:35receive
- 29:37every kind of emails right here
- 29:41and now if I reload this page even if I
- 29:45try to access the page verify email I'm
- 29:48redirected on the home page because this
- 29:50is the default Road at the moment
- 29:52the problem I see here is that Mary can
- 29:56actually access to admin panel as well
- 29:58which is not correct Mary is a regular
- 30:01user what she should be able is to
- 30:04probably leave a comment on article
- 30:06upvote download but she should not be
- 30:09able to access to admin panel unless we
- 30:12Define it so but I'm going to Define it
- 30:15not like this I want only admin users to
- 30:18be able to access and they will be
- 30:20managing all kind of content and regular
- 30:23users will be able to just comment
- 30:25upload download and do things like that
- 30:28so we should restrict that and to do so
- 30:31I'm going to introduce permissions
- 30:34package from Speedy so let's search for
- 30:38T permissions and the very first link
- 30:41from
- 30:44spity.d.be domain will be the
- 30:47permissions package let's click on the
- 30:50installation that's a very powerful
- 30:52package so let's scroll down below and
- 30:54find the installation section we're just
- 30:56going to run composer require first and
- 30:59then this will be automatically done we
- 31:01don't need to do this we need to publish
- 31:03the config as well as the migration file
- 31:05we're going to execute that and we can
- 31:08clear the cache and finally we're going
- 31:09to execute PHP Artisan migrate okay then
- 31:12we're gonna do a few other things like
- 31:15uh
- 31:16uh entity has roles and probably defined
- 31:19roles as well but let's start from the
- 31:21very first step what we need to do right
- 31:24here like the prerequisites and
- 31:26everything is okay we satisfy those and
- 31:29now let's open the terminal so in the
- 31:32terminal I'm actually writing npm run
- 31:34Dev so I'm going to open second terminal
- 31:36and I'm going to log in inside the
- 31:39container vendor
- 31:42Bean sale Bash
- 31:47and now I am in the container and I'm
- 31:49going to execute composer require let me
- 31:52copy the Second Step which will be PHP
- 31:54Artisan vendor publish let's copy this
- 31:57and their required was installed let's
- 32:00now run PHP Artisan vendor publish those
- 32:02two files have been published
- 32:04permissions PHP inside the config and
- 32:07the migration file you can have a look
- 32:09at the migrations what is going on if
- 32:11you are interested you can find this in
- 32:13the database migrations right here and
- 32:16you will see that this creates couple of
- 32:17tables and this is the basically the
- 32:21whole migration which you can explore if
- 32:23you're interested okay now let's apply
- 32:25PHP
- 32:27Artisan
- 32:29optimize clear
- 32:32and it was cleared then PHP Artisan
- 32:35migrate
- 32:38all right if we have a look in the
- 32:40database schemas you can access to the
- 32:42database client uh
- 32:45through the um to the MySQL which is
- 32:49actually running in the docker and I'm
- 32:51going to check right now the database in
- 32:53the page performs database client just
- 32:55refresh this keymind we see a couple of
- 32:57tables like roles model has permissions
- 33:00module has roles and so on okay so those
- 33:03tables we are created now I'm going to
- 33:06open user.php and I'm going to introduce
- 33:10a new trade right here has roles it
- 33:14comes from Speedy permission trades has
- 33:17Rose and now
- 33:19I'm going to actually Implement an
- 33:22interface so basically regarding
- 33:23permissions we did most of the things
- 33:25let me try to do one additional thing to
- 33:28create the role actual role so the we
- 33:32have the database Cedar right here uh
- 33:34and actually I'm gonna check what users
- 33:37we have we have uh zura and Mary and I'm
- 33:41going to create now admin user okay and
- 33:43I'm going to Define also admin role as
- 33:46well I'm going to comment this post
- 33:49Creation in the database theater I don't
- 33:51want to create posts that was just for
- 33:53testing purposes in the first part and
- 33:55by the way if you haven't checked the
- 33:57first part first I recommend to check
- 33:59check it and then continue watch the
- 34:02second part and then now let's create a
- 34:05user so let's call this admin user that
- 34:09will be user
- 34:12Factory
- 34:13let's import the user
- 34:16app modules user right user Factory
- 34:19create let's provide right here email
- 34:24will be admin at example.com let's
- 34:28provide name it will be admin and let's
- 34:33provide password
- 34:35that will be back Crypt
- 34:38it's provided admin123 okay that's the
- 34:41password and now let's create admin role
- 34:44as well that will be
- 34:47role and that will be spotty permission
- 34:51models create and we have to provide a
- 34:55name of the role
- 34:57that will be admin so the role is
- 35:01actually created and then on admin user
- 35:04I'm gonna call assign role so this
- 35:07assign role method is not seen by Page
- 35:11performing it does not autocomplete but
- 35:14this assigned role comes from the trade
- 35:16we added on the user model so if we just
- 35:20Define an annotation right here that the
- 35:22admin user variable is actually an
- 35:24instance of app models user then when we
- 35:28try to call assign role page question
- 35:29sees that and we can provide right here
- 35:32admin role variable and whenever the CD
- 35:36is executed it's going to create the
- 35:37user create the role and then assign the
- 35:40role to that user so let's bring up the
- 35:43terminal and I'm going to execute PHP
- 35:45Artisan
- 35:47nanometrate DB colon seed
- 35:50so seating database has been completed
- 35:52let's now open database then we have new
- 35:55admin user if we open roles we have
- 35:58admin role and if we check model has
- 36:03roles we're going to see that the model
- 36:06ID which is the currently added 11 ID
- 36:11user has role id1 okay so we defined
- 36:16those roles which is perfect
- 36:19now let's try to basically log in with
- 36:23the new user adminate example.com and
- 36:26let's let's just reload the page sign
- 36:30out and now I'm going to use admin at
- 36:33example.com
- 36:34admin123 and look at this so we are
- 36:38right now logged in as an admin user but
- 36:41actually if I try to log in with Mary
- 36:45let's use the auto compilation
- 36:49now we are still in the admin so we
- 36:51created role we created admin user but
- 36:53we haven't defined a restriction for
- 36:56normal users to the admin for this again
- 37:00we are going to open the user PHP and
- 37:02we're going to implement right here an
- 37:05interface called
- 37:07uh filament how is it called I just
- 37:10forgot filament user I think that's it
- 37:12filament user yes and we have a red
- 37:16underline right here this uh it comes
- 37:18from the PHP showroom it indicates that
- 37:20we need to implement a method from the
- 37:22straight so if we just hit the control
- 37:24and mouse on this filament user we see
- 37:26that it has the following following
- 37:29method defined and that is can access
- 37:32filament in phpstorm I can just hit alt
- 37:35and enter and this gives me a couple of
- 37:38options Aid method is tabs click OK and
- 37:42at the very bottom we're going to see
- 37:43this method can access filament and
- 37:46we're going to return true or false from
- 37:48here if I just return true basically
- 37:51every user will be able to access if I
- 37:53return false none of the users will be
- 37:56able to access so if I just reload now
- 37:59Mary is not be able to access even admin
- 38:01will not be able so we need some kind of
- 38:03condition right here okay so this has
- 38:06role we're going to call a method has
- 38:08roll
- 38:09excuse me has a role and specify the
- 38:13role name so only those users should be
- 38:16able to access that interface if the
- 38:20user basically has that specific role
- 38:24admin role in this case so if I just
- 38:26roll the page we are not able to access
- 38:29this so I'm going to inspect because I
- 38:32want to clear the session I'm going to
- 38:34go in the application uh cookies and I'm
- 38:37going to clear everything just reload
- 38:39the page and it redirects us to the
- 38:42login and we try to basically again let
- 38:46me actually try to log in with Mary we
- 38:48see permission forbidden but if I try to
- 38:52reload the website we are actually
- 38:55logged in with Mary and I can log out
- 38:57from here as well okay let me reload the
- 39:00page and now let's try to access with
- 39:02admin user
- 39:04admin hit the enter now we are able to
- 39:08access filament admin admin panel which
- 39:11is awesome so the admin users can create
- 39:13categories posts text Regis manage the
- 39:16content and normal users can log in on
- 39:19the website we haven't defined any any
- 39:21functionality which is relevant for the
- 39:24normal users which are optimized on the
- 39:26website but still we have the
- 39:28authentication implemented which is
- 39:30which is great
- 39:32here I have generated users resource so
- 39:36from admin I can manage users as well I
- 39:38think this is uh generated outside of
- 39:40the recording so you cannot find this
- 39:43actually in the first part but
- 39:45generating users resource is pretty
- 39:48identical generating post resource so I
- 39:50just did this because I needed users in
- 39:53the admin as well
- 39:55but the most important thing right here
- 39:57is that every user which is created
- 39:58right now from admin needs to have admin
- 40:02role okay if I just create new user it
- 40:05will not have admin role and this is
- 40:07something we are going to change so I'm
- 40:11going to go in the app filament and
- 40:15let's open user resource and open this
- 40:18create user right here and we have to
- 40:21customize this we have to add a new
- 40:24admin role to every user when that is
- 40:28actually created so right here I'm going
- 40:30to create create new function handle
- 40:33record creation which is a protected
- 40:36function and we can actually customize
- 40:38this this handle record creation if we
- 40:40just fold the follow this it gets the
- 40:44model based on the class and creates
- 40:45that so whenever this is called we can
- 40:49take these as already created user and
- 40:54say that in a very table right and we
- 40:56know that every user has that has that
- 41:01trait as roles so basically if I
- 41:07let's call in the create user so if I
- 41:09call on that user
- 41:13hold on if I call this a sign role again
- 41:16after completion doesn't work because
- 41:18PHP stream doesn't understand that this
- 41:20user is an instance of app modules user
- 41:22so I generally tend to Define this
- 41:24because I love when people store
- 41:26autocomposite for me it's also very easy
- 41:29if you want to search then in your
- 41:31entire project where are the instances
- 41:34of that user basically it will find that
- 41:37place as well if I just remove The
- 41:39annotation and go in the user PHP and
- 41:42right click on the class and try to find
- 41:44the usages of that class it will not
- 41:48find that specific
- 41:51alone that specific variable because it
- 41:54has no idea that this is an instance of
- 41:56app models user right if I add this
- 41:59annotation and then call this find
- 42:01usages then it will find end it's also
- 42:04good if you want to find out where you
- 42:06have all the instances of the specific
- 42:07specific model so in this case I'm going
- 42:10to try to call assign role on that and
- 42:13provide admin
- 42:15uh
- 42:16admin right here and finally we need to
- 42:19return user
- 42:23my keyboard
- 42:25I just don't like my keyboard I'm going
- 42:28to replace it
- 42:29okay so the user creation process is
- 42:32like this and if I now go in the admin
- 42:35and try to create
- 42:38new uh new user so let's call this shown
- 42:42let's give it
- 42:44Sean at example.com email verify that is
- 42:48something we can Skip and the password
- 42:50will be
- 42:52something secure okay and let's hit
- 42:55create
- 42:57uh let's hit never okay so the user was
- 43:00created now the most important thing is
- 43:02to go in the database check the database
- 43:05let's open users first we see that John
- 43:09is created with ID 12. and second is the
- 43:14model has rows let's open this and now
- 43:16we see that there is a rule one assigned
- 43:19to Model 12 okay however I think the
- 43:22user might not be able to log in because
- 43:24email verified is actually null and this
- 43:27is something we probably need to also
- 43:28fix let me actually try to sign out and
- 43:32try to log in with John
- 43:37yes I am not able to to log in now let's
- 43:40open users and I'm gonna let's actually
- 43:43try to log in with admin
- 43:48admin123
- 43:49okay good let's open users and we can
- 43:52edit this and provide
- 43:55uh provide some some value inside email
- 43:58verified it and whenever we do this this
- 44:01password is by the way required so this
- 44:03form is just a very very basic form I
- 44:06just generated as I mentioned outside of
- 44:07the recording I haven't customized that
- 44:09at all the password should not be
- 44:11required whenever we are updating the
- 44:14user password should be optional and
- 44:17even we should have probably two fields
- 44:20for the password password and password
- 44:21repeat so that if you want to change a
- 44:24password reset the password for a
- 44:25specific user you should be able to uh
- 44:28provide it you should provide it twice
- 44:30just to avoid any kind of mistakes so in
- 44:33this case for Simplicity I'm just going
- 44:34to provide from one to
- 44:37um
- 44:38from one two like whatever and hit save
- 44:42changes okay that was saved but now
- 44:45whenever we try to create new user this
- 44:48email verify that needs to be set
- 44:50automatically okay so let's customize
- 44:53this form
- 44:54and let's go in the where's that create
- 44:58user I know that is
- 45:05our resources
- 45:07user resource
- 45:10create where is the form
- 45:15down below here we see user resource
- 45:18okay and so this is the form uh we can
- 45:21completely remove this email verify that
- 45:23we don't need to provide this twice uh
- 45:27sorry we don't need to provide this at
- 45:29all we need to provide password probably
- 45:32twice let's remove required from here as
- 45:35well
- 45:36we can provide right here
- 45:39the method using which we can hide the
- 45:42password field when we are editing the
- 45:44user as well so like the password the
- 45:47input field is the password max length
- 45:49and let's provide right here that should
- 45:51be hidden on
- 45:54edit so we don't want this to be on edit
- 45:59however we can also provide that this
- 46:03needs to be visible
- 46:05visible on create
- 46:10so in this case we need to Define
- 46:12probably two password Fields let's do
- 46:14like this so the one password with the
- 46:16password max length this is hidden on
- 46:19edit
- 46:20let's select this and the second one
- 46:23is
- 46:25visible on Create and we can also
- 46:27specify right here required
- 46:31okay so that must be required and that
- 46:35is
- 46:36visible on create let's save this and
- 46:40have a look reload the page this is user
- 46:43creation so we see password actually
- 46:46twice which is something we shouldn't
- 46:49see
- 46:50uh let's hide this on create as well
- 46:57okay let's try to have this all in a
- 46:59single input field password required not
- 47:02the required a max length and then let's
- 47:05just provide hidden on edit and then
- 47:09provide required and visible oncreate
- 47:12let's see if this gives us exactly what
- 47:15we want
- 47:17okay the password is still visible on
- 47:20user creation that's correct so it
- 47:22should be visible on user creation but
- 47:24the interesting thing is update so if I
- 47:26click update we don't see password Here
- 47:30we choose
- 47:32which is exactly what we wanted in this
- 47:34case however as I mentioned if you want
- 47:37to reset the user password you won't be
- 47:39actually be able to do this
- 47:42so in this case I'm going to add one
- 47:45more method
- 47:46and that will be confirmed so the
- 47:50password needs to be confirmed and we
- 47:53need a second field for password
- 47:55confirmation as well and let's give it
- 47:58the proper name confirmation
- 48:01all right and the password confirmation
- 48:03also needs to be visible on let's
- 48:07actually take this part
- 48:13so it's a password max length hidden on
- 48:16edit required visible on create blah
- 48:19blah let's now reload the page
- 48:22on edit we don't see that
- 48:24uh let's that was actually View
- 48:28I want to submit this form just make
- 48:30sure that even though we just we don't
- 48:33display it it is not required we have
- 48:35this required function here so click on
- 48:37save that was actually saved perfect uh
- 48:40if we go in the users we see John 2 that
- 48:43was updated now a new we have password
- 48:46and password confirmation let's create
- 48:48Tom for example
- 48:51we provide password if I don't provide
- 48:55the password confirmation and hit create
- 48:58we get this error if I provide incorrect
- 49:01password click create we get this error
- 49:04perfect
- 49:05so now we have possibility to
- 49:08we have possibility to set the password
- 49:12of the user
- 49:13okay did I make any mistake
- 49:16let's provide password properly
- 49:21password confirmation field doesn't
- 49:24okay that looks like
- 49:27we don't have it as we should have so
- 49:31the password
- 49:32is password max length in required and
- 49:35it is confirmed password confirmation
- 49:41okay great again let's provide password
- 49:49hit create it doesn't seem to be working
- 49:53okay let's check the source code and I
- 49:58think that is the problem it's a stupid
- 49:59mistake so password confirmation
- 50:01obviously doesn't need confirmed role
- 50:04the confirmed rule is necessary on the
- 50:07password itself so if I save this and
- 50:10hit create now the user was created so
- 50:14that's perfect however speaking of the
- 50:16email verify that that is still null for
- 50:19every new user so let's just open that
- 50:21create user
- 50:24and maybe before before the user is
- 50:28created inside the data we can provide
- 50:31email verified
- 50:34it
- 50:35is just current time
- 50:38let's provide
- 50:40time here or I think we can provide
- 50:43carbon now as well so I save this
- 50:48now let's try to add new user
- 50:51Let It Be Gene in this case
- 50:54and gym
- 50:59and let's provide password
- 51:05at the end okay password confirmation
- 51:08does not match
- 51:11hit create
- 51:15okay email verify that was not saved
- 51:20okay we can we can create another method
- 51:23which just like we did in the post
- 51:24resource if we
- 51:27open these post resource here
- 51:31note here sorry right here in this post
- 51:35resource we have these create post and
- 51:38we have this mutated form data before
- 51:40create okay so we just copy this and go
- 51:44in the create user and let me paste this
- 51:48here and mutate form data before create
- 51:51we provide
- 51:53email verify that and let's provide
- 51:56carbon now
- 51:58let's remove this from here I save it
- 52:01and let's try to add new user let's give
- 52:05it test in this case
- 52:08let's give it short password click
- 52:10create
- 52:12okay email verified it is still and not
- 52:15provided
- 52:17and
- 52:19I think the reason might be that this is
- 52:23excluded and not provided in the
- 52:26fillable
- 52:28and that is added in the casts so we
- 52:31need to add this in the fillable and
- 52:34then it will work
- 52:36let's try to add new user
- 52:38S2
- 52:41let's provide short password click
- 52:44create and this worked this time so now
- 52:47we have this test user which has even
- 52:49verified it and this is admin user by
- 52:52the way and if I now try to sign out and
- 52:56try to log in with the test two let's
- 52:59try to log in first with the test
- 53:02it doesn't work because the email is not
- 53:05verified but now if I try to log in with
- 53:07test2
- 53:09okay it doesn't work
- 53:11either
- 53:13and I think the reason might be that the
- 53:15password
- 53:17is it saved properly let's check this
- 53:20not sure the passwords are saved and
- 53:23passwords are saved as plain text
- 53:24obviously we haven't implemented this
- 53:27part so if we open user resource uh not
- 53:30the user resource but create user
- 53:33and right here mutate form data before
- 53:36create
- 53:37so we want to
- 53:40hash the password before create so we're
- 53:43going to call Big creeped here
- 53:46and
- 53:47then we provide a data password
- 53:52just like this
- 53:54now let's create test three in this case
- 53:57we need to log in with admin
- 54:00please try again three seconds okay
- 54:04one two three
- 54:06now let's go in users and let's create
- 54:11and by the way that was an extra
- 54:13security of filament which I liked so if
- 54:16you try too many attempts incorrect
- 54:18attempts then it tells you to wait
- 54:20that's I think
- 54:23really good let's create now one more
- 54:26user
- 54:27in this case the password encryption
- 54:30should work
- 54:31hit create okay it doesn't work let's
- 54:34give it short password
- 54:36okay so we have that now let's check the
- 54:40database first
- 54:42okay here we see encrypted password now
- 54:45let's sign out
- 54:47and try to sign in and that works this
- 54:50time okay now every user which is
- 54:53Created from filament admin is an admin
- 54:56user and the password the email is
- 54:58verified and password is encrypted and I
- 55:01guess we can delete all the previous
- 55:03users because their passwords are not
- 55:05encrypted okay now I'm going to
- 55:08implement one very important and really
- 55:11cool feature and there's going to be
- 55:12upvote and download of Articles every
- 55:16authorized user will have this ability
- 55:17to click a button and upvote article and
- 55:21give a credit to the article and in the
- 55:24future maybe based on the number of
- 55:25apples on certain article we can promote
- 55:28that and show on the home page or
- 55:30showing recommended articles and do some
- 55:33things like that so let's start
- 55:36implementing this really cool feature
- 55:37and I'm going to do this using laravel
- 55:40Live Wire
- 55:42uh filament PHP behind actually is using
- 55:45whatever Live Wire but we haven't used
- 55:48on the front end it at all so I'm going
- 55:51to open the documentation a live wire
- 55:54and let's have a look
- 55:56so let's go in the docs and I'm gonna
- 55:59like um give you a quick overview so
- 56:02right here you can find the
- 56:03documentation let's click on install
- 56:06Live Wire we need to run composer
- 56:08require but as I mentioned because we
- 56:10already have a filament PHP which
- 56:12internally uses a lot of a live wire we
- 56:15can skip that section and we can just
- 56:18import that live wire Styles and scripts
- 56:20in our layout just to make sure we have
- 56:23Live Wire installed let's open our
- 56:25project
- 56:27let's open composer composer log file
- 56:31and inside there let's search for
- 56:33Livewire and if we see that in somewhere
- 56:36as a dependency it means that it is
- 56:38included and if we see if we check the
- 56:40package uh that is Livewire late rate
- 56:45limiter and the live wires dependency of
- 56:49it and if we just follow that and find
- 56:51out internally it's going to be finally
- 56:54a dependency of filament PHP okay
- 56:58so we already have Live Wire installed
- 57:01now we need to register Styles and
- 57:04scripts in our application so I'm going
- 57:06to open layout up blade PHP and in the
- 57:11header let's do this before white let's
- 57:15include the Styles and at the very
- 57:17bottom they are like a before the
- 57:20closing of the body tag I'm going to
- 57:23include Live Wire Scripts
- 57:26okay so far so good and then having a
- 57:29look at the quick start we can already
- 57:31generate a component so in this case I'm
- 57:34going to call my component let's start a
- 57:39new terminal vendor being sale Bash
- 57:44all right and now let's generate a live
- 57:47wire component and I'm going to call
- 57:49this upfold download component okay
- 57:52that's going to be like your two buttons
- 57:54uh hands up thumbs up and thumbs down
- 57:57and yeah just like this we're going to
- 58:00show number of upvotes in number of down
- 58:02rules on a particular article so let's
- 58:06click enter right here right so it asks
- 58:09me whether I want to start the Ripple or
- 58:11not I have actually already started it
- 58:13so I'm going to type a no right here so
- 58:16the Live Wire component was actually
- 58:18generated and if we open up
- 58:21HTTP Live Wire we see this apple
- 58:24download there's a very basic Live Wire
- 58:26component and it renders the following
- 58:28view file and that view file already
- 58:32exists upvote Dash download play there's
- 58:36an empty blade file okay so we have this
- 58:39Live Wire component but now let's focus
- 58:42on the database right so we need the uh
- 58:46actually before we do the database let's
- 58:49put some something right here like a
- 58:51test and then let's open view file
- 58:56there's going to be the article
- 58:58interview and inside that inside that
- 59:02white background card
- 59:07at the very bottom maybe we can use Live
- 59:10Wire colon and the component name in
- 59:15this case it's going to be upfold down
- 59:17vote that's going to be the component
- 59:19all right so I save this I think we need
- 59:24Dash right here upload Dash download so
- 59:27I save this and now let's open the
- 59:29front-end side and click on the very
- 59:30first article we are in the inner page
- 59:32then right here we see test okay so the
- 59:34Live Wire component is actually rendered
- 59:36from here now let's focus on the
- 59:38database because we're going to save
- 59:39this app volts and downloads in the
- 59:42database
- 59:43I'm going to generate new model and
- 59:45migration HP artisan make model upvote
- 59:51download let's call this same name as
- 59:54the component and dash M we need this as
- 59:57well now let's open migration file
- 1:00:03right here and let's define few Fields
- 1:00:06like first I'm going to define a Boolean
- 1:00:08type of field and it's going to be ease
- 1:00:10upvote
- 1:00:12okay so if this will be true it means
- 1:00:16that user hit the upvote button if this
- 1:00:19will be false it means user hit the
- 1:00:21download button at the same time user
- 1:00:23cannot hit upvote and download buttons
- 1:00:26on the same article so it's going to be
- 1:00:28either port or download so this is how
- 1:00:31I'm gonna do this and we'll also provide
- 1:00:34right here two foreign IDs
- 1:00:37uh one will be post ID on which post the
- 1:00:41upvote or download happens that
- 1:00:44references to ID on table hosts and we
- 1:00:49can also specify
- 1:00:51um own delete what should happen on
- 1:00:53delete uh Cascade let's provide Cascade
- 1:00:56here I'm going to duplicate this same
- 1:00:58line and it will also provide the user
- 1:01:01ID who made this upfold or download the
- 1:01:05table will be users and we can leave
- 1:01:07this Cascade so it is as simple as that
- 1:01:10migration migration excuse me is ready
- 1:01:13now let's open Terminal and execute PHP
- 1:01:17Artisan migrate
- 1:01:19okay the migration was applied and if we
- 1:01:22check the database we are going to see
- 1:01:25down below upload downloads table
- 1:01:27perfect let's open up vote download uh
- 1:01:32we need model
- 1:01:34upvote download
- 1:01:36and inside fillable let's add those
- 1:01:41three Fields is up fold
- 1:01:45we need post ID
- 1:01:48and we need user ID
- 1:01:51all right
- 1:01:52so far so good now let's open this
- 1:01:55upload download Livewire component and
- 1:01:58in the render we are going to select how
- 1:02:02many apples and how many downloads these
- 1:02:05particular article has but we don't have
- 1:02:07any identifier for this particular
- 1:02:10article so what we are going to do
- 1:02:13uh this upper blade I think we can close
- 1:02:16this I'm going to close Ian as well I
- 1:02:19will only leave those files which is
- 1:02:20relevant for me at the moment I'm going
- 1:02:22to close the migration as well inside
- 1:02:24the view so from here I'm going to
- 1:02:26provide post so that's going to be the
- 1:02:29actual post on which we're going to show
- 1:02:32up for it and download we're going to
- 1:02:34accept that post variable
- 1:02:36inside the Live Wire component like
- 1:02:41here
- 1:02:42we're going to create a mount function
- 1:02:44in the mount function will accept this
- 1:02:48post
- 1:02:49first we need to import this post model
- 1:02:52here then I'm going to create uh
- 1:02:56oblique
- 1:02:57host variable and
- 1:03:01public and then this
- 1:03:06host will be given post
- 1:03:08all right and now here inside render I
- 1:03:11have access to this post and I can
- 1:03:13select how many upvotes or downloads
- 1:03:16these post has but let's uh first to the
- 1:03:19front-end side and I'm going to now open
- 1:03:23hero icons which is a like SVG icons
- 1:03:27really easy to use we're just gonna look
- 1:03:30for
- 1:03:32thumbs up or something like this here we
- 1:03:34have those two icons and we just need
- 1:03:36svgs there's like a no need to install
- 1:03:39or require any CSS or anything we just
- 1:03:42can copy SVG files and let's open this
- 1:03:45up for download and I'm going to create
- 1:03:47two buttons and that's going to be for
- 1:03:50upvote so I'm going to paste this here
- 1:03:53and the second button will be for
- 1:03:56download let's copy SVG and paste this
- 1:04:00here
- 1:04:01all right so that's perfect now let's
- 1:04:05add couple of CSS classes to those
- 1:04:08buttons as well
- 1:04:11so we're going to give it display flex
- 1:04:13and items same term I'm going to give it
- 1:04:16also Gap two uh and let's give it also
- 1:04:20on Hover the text should be text blue
- 1:04:24like a 500 and let's give it also a
- 1:04:28transition all to have this nice effect
- 1:04:31on Mouse over and right here and here we
- 1:04:34are going to Output two variables number
- 1:04:37of upvotes and number of downvotes
- 1:04:40down below we need down volts and we
- 1:04:44need to pass these two variables from
- 1:04:47the Live Wire component into blade file
- 1:04:51so I think we don't need this model I'm
- 1:04:54going to close that and let's open the
- 1:04:55component and there are two ways to pass
- 1:04:59data from Live Wire component to Blade
- 1:05:03file one is to declare that variable as
- 1:05:06a public property of the class and then
- 1:05:08can this can be accessed inside the
- 1:05:10blade file in this case if we want to
- 1:05:13access post we can access easily from
- 1:05:15these view blade file the second
- 1:05:18approach is to pass these two variables
- 1:05:21in a view so this is what I'm gonna do
- 1:05:24and I like second approach because
- 1:05:26whenever something is changed in a
- 1:05:28component like even Handler is triggered
- 1:05:31or some sort of data is updated
- 1:05:35then this render method is called and
- 1:05:39the if we select some kind of data then
- 1:05:42the view also will be called and view
- 1:05:45will be updated very easily okay so now
- 1:05:48let's select up folds and that's going
- 1:05:51to be Apple download from modal we're
- 1:05:54going to run where
- 1:05:56host ID
- 1:05:58equals to this
- 1:06:01host ID and we are going to we're going
- 1:06:07to add another weird
- 1:06:09where
- 1:06:10is upvote
- 1:06:13equals one or true
- 1:06:16and finally we're going to call count
- 1:06:19okay so this will be number of upfolds
- 1:06:23uh that has been made on that particular
- 1:06:27post uh we can move this where and count
- 1:06:31down to make it like more readable so
- 1:06:34I'm going to duplicate this and the
- 1:06:36second one will be downloads
- 1:06:39and right here we're going to provide
- 1:06:41false number of downwards on that
- 1:06:45particular article okay so that's
- 1:06:47perfect now let's provide right here
- 1:06:49compact
- 1:06:51up Folds and downloads now I'm Gonna
- 1:06:56Save this and let's test this so far
- 1:06:59let's open the front and side and
- 1:07:02we have our basically let's reload okay
- 1:07:06there is gone and at the very bottom we
- 1:07:08have these two buttons with a zero okay
- 1:07:11let's give
- 1:07:13small CSS classes here let's give it
- 1:07:16flex and gap of two
- 1:07:19okay perfect we have up folding download
- 1:07:21the how over effect works as well
- 1:07:24now let's Implement actually clicking on
- 1:07:26that button let's call the inner
- 1:07:29component and I'm going to create a
- 1:07:33component sorry I'm going to create a
- 1:07:36method let's call this upfold download
- 1:07:42okay so this method will be called
- 1:07:44whenever user clicks on app Vote or on
- 1:07:46download and actually I'm going to
- 1:07:48accept a parameter right here whether
- 1:07:50this is an upfold or download
- 1:07:53so why I'm doing this as a single method
- 1:07:56and not two separate methods like up
- 1:07:58fold is a separate method in download as
- 1:08:00a separate method because we're going to
- 1:08:03have very similar logic in those both
- 1:08:07methods if we're going to do it
- 1:08:09separately and I don't like code
- 1:08:11duplication so that's why I prefer to
- 1:08:14write a dry code and just give a
- 1:08:17parameter right here okay and calling
- 1:08:20this up for download method from the
- 1:08:23component from the blade file will be
- 1:08:25super easy we just provide right here
- 1:08:28wire colon
- 1:08:30uh Clique that's the event name and
- 1:08:34upvote download and then we can provide
- 1:08:37the argument okay by default the
- 1:08:39argument is true so we can provide only
- 1:08:43false right here if we don't want it to
- 1:08:45be upvote if we want it to be download
- 1:08:48right so so far so good but in order to
- 1:08:52upvote or download to happen the user
- 1:08:56needs to be authorized right so we can
- 1:09:00check if the user is authorized Android
- 1:09:02direct to login page but first i'm going
- 1:09:04to actually get the user because if the
- 1:09:06user is authorized I need to access the
- 1:09:09user information in any case so I'm
- 1:09:13going to call request user
- 1:09:17so I'm going to get the current user and
- 1:09:19I'm going to add also annotation this is
- 1:09:21an instance of app modules user because
- 1:09:23uh like I really like to do this in
- 1:09:27terms of I need some kind of Auto
- 1:09:28completion or things like that then this
- 1:09:31works excellent so if the user does not
- 1:09:34exist we are going to Simply return from
- 1:09:37here and let's call this redirect we're
- 1:09:40going to redirect user to a login login
- 1:09:43page okay
- 1:09:46however if the user exists there is one
- 1:09:49additional check to do if the email is
- 1:09:52verified for that user okay and this is
- 1:09:54the case where Auto completion works
- 1:09:57perfectly because I added the sanitation
- 1:09:59right here so if the user has a verified
- 1:10:03email here more more correctly if the
- 1:10:06user doesn't have a verified email we
- 1:10:09are going to return
- 1:10:11hold on return
- 1:10:13these redirect
- 1:10:16oops
- 1:10:18and in this case I'm going to provide
- 1:10:19the road function and pass the actual
- 1:10:22Road name where the redirect user to the
- 1:10:26um like email verification page and if
- 1:10:29we open now out PHP from the roles which
- 1:10:32is generated by lateral Breeze and
- 1:10:35scroll down below we should see this
- 1:10:37verify email URL with verification
- 1:10:41notice name Road name so this is the
- 1:10:44road name we're going to use in this
- 1:10:46case so I'm going to provide it right
- 1:10:48here
- 1:10:49okay so and at the very bottom it means
- 1:10:52that the user is successfully
- 1:10:54authenticated on the website and the
- 1:10:57email also is verified so now we are
- 1:11:00going to Simply
- 1:11:01um
- 1:11:02make a record in the database or if the
- 1:11:05record already exists we're going to
- 1:11:07delete that record so first let's select
- 1:11:10if there already exists Apple download
- 1:11:13record uh in the database
- 1:11:16so let's select upvote download equals
- 1:11:20that's going to be
- 1:11:22from the model let's write weird
- 1:11:25for that specific post post ID
- 1:11:29underscore ID equals to this host ID
- 1:11:34okay we need another where in this case
- 1:11:38we're going to provide user ID we are
- 1:11:40interested if there is upvote or
- 1:11:43download for that specific user these
- 1:11:46are not this in this case we just need
- 1:11:48user ID
- 1:11:50okay so we select that and we just need
- 1:11:53to get our first record
- 1:11:57from here now if this does not exist
- 1:12:01there's no upvote download record then
- 1:12:05we're going to do the following so we're
- 1:12:07going to create new record
- 1:12:09upload download create
- 1:12:12and we are going to pass is up Folds
- 1:12:19excuse me
- 1:12:22is up fold will be the given parameter
- 1:12:24whether we are doing upvote or download
- 1:12:28we're going to provide post ID
- 1:12:32this
- 1:12:34host ID and we're going to provide user
- 1:12:38ID
- 1:12:40as well
- 1:12:42user ID
- 1:12:45okay that's perfect and I think we can
- 1:12:49return and don't continue anything below
- 1:12:51from here
- 1:12:53then if the app will download already
- 1:12:56exists we're gonna do two things like if
- 1:13:01the user is clicking upload button
- 1:13:04then we're going to check if the record
- 1:13:07which exists in the database is
- 1:13:09for up fault
- 1:13:12we are going to delete that record
- 1:13:15completely
- 1:13:17okay
- 1:13:20so let's check if
- 1:13:23the action what we're going to do is
- 1:13:26upvote and the record up for download
- 1:13:30maybe that's a confusing let's call this
- 1:13:32model okay I'm going to rename this and
- 1:13:34call this model
- 1:13:35that's a database model if the model in
- 1:13:38the database has is upvote
- 1:13:42so if we are doing upvote but in the
- 1:13:44database there is already up for type of
- 1:13:47record simply we are going to delete the
- 1:13:50model okay it means that user wants to
- 1:13:53remove his app vote simply take back his
- 1:13:57upvote
- 1:13:59we're going to do an else statement as
- 1:14:01well if this is not the case uh then uh
- 1:14:06okay let me first do another if right
- 1:14:09here and then we can the the else case
- 1:14:11will be very straightforward okay so if
- 1:14:14user is doing upload in the model
- 1:14:16um already has upload we delete that or
- 1:14:19there's another case if the user
- 1:14:22wants download
- 1:14:24and model
- 1:14:29already has download is
- 1:14:33upvote equals false okay in this case we
- 1:14:37do the same thing like if the user has
- 1:14:39previously hit the download button and
- 1:14:41let's call it dislike this is I think
- 1:14:44very easy to say so if the user
- 1:14:45previously disliked the article it now
- 1:14:49wants to remove the dislike then we
- 1:14:52delete that so in this case we have
- 1:14:55model and in model we specify is upvote
- 1:15:02equals whatever is given upload
- 1:15:07okay
- 1:15:08so this is what we are going to do and
- 1:15:10then on model
- 1:15:13we are going to call Save
- 1:15:16so this will update the existing upvote
- 1:15:19download record and whenever this is
- 1:15:22executed this function is executed and
- 1:15:25because this makes some like
- 1:15:27modifications in the database as well
- 1:15:30the re-render method will be executed
- 1:15:33and the the selects will run and the
- 1:15:37counts of each of the items will be
- 1:15:40already modified
- 1:15:42so if you don't believe me let's reload
- 1:15:44the page and click upvote and as you see
- 1:15:47right here we see one if I just roll the
- 1:15:50page one is there so record was
- 1:15:53successfully made in the database now if
- 1:15:55I click upvote again it removes the
- 1:15:57upfold and now we see Zero again now
- 1:16:00let's click download we see Zero click
- 1:16:03download again sorry we saw one and now
- 1:16:07we see Zero now if I click up vote and
- 1:16:10then I click download then look at this
- 1:16:13so it actually worked properly it
- 1:16:15changed existing upload record into
- 1:16:18download
- 1:16:20so I think that works excellent and that
- 1:16:23works exactly as I want except that I'm
- 1:16:25going to add one additional thing
- 1:16:28if the currently authorized user has
- 1:16:31this particular article upvoted we're
- 1:16:34going to show this button blue
- 1:16:36so we're going to do this in the render
- 1:16:38method and I'm going to Define a
- 1:16:40variable here has upvote
- 1:16:44and I'm gonna also add a comment right
- 1:16:47here which perfectly describes what this
- 1:16:50variable should do so that's going to be
- 1:16:52the status whether the current user has
- 1:16:54upvoted the post uh or not and this
- 1:16:57might be now true or false if it's null
- 1:17:00it means that user has not taken any
- 1:17:03action has not upvoted or
- 1:17:06downvoted that article if it's a true
- 1:17:09user upvoted if it's false user
- 1:17:12downloaded that particular article okay
- 1:17:16I'm going to query also a user let me
- 1:17:18actually grab this from here
- 1:17:20I need the current user and I'm going to
- 1:17:23make a query in the database first I'm
- 1:17:26going to check if the user is authorized
- 1:17:29if that exists then let's actually
- 1:17:32select a variable from the up for
- 1:17:35download we can call this model or
- 1:17:37current status let's call this model
- 1:17:39okay
- 1:17:41model equals upvote download where
- 1:17:47provide post ID
- 1:17:49equals
- 1:17:52this host ID and we also provide the
- 1:17:58user ID
- 1:18:03user ID and we just select the very
- 1:18:08first record
- 1:18:10all right let's move this where in first
- 1:18:14down so we select the very first item
- 1:18:17for this particular user and the um for
- 1:18:21this particular post and now we're gonna
- 1:18:24check if the model exists so if there's
- 1:18:27a adap photo download for that specific
- 1:18:30model then his upvote basically equals
- 1:18:34whatever is the models is upvote
- 1:18:40okay
- 1:18:41but I'm going to add right here double
- 1:18:43exclamation
- 1:18:45just because this is up fold will return
- 1:18:48true uh not true uh it will return one
- 1:18:51or zero because the database will hold
- 1:18:54the values into one and zero for Boolean
- 1:18:57mySQL database and using this double
- 1:19:00exclamation we're converting this into
- 1:19:02an actual Boolean and now in this view
- 1:19:05we can pass his upvote and now let's
- 1:19:10open this upvote download blade PHP and
- 1:19:13I'm going to add CSS classes so first
- 1:19:16right here
- 1:19:17his upfruit
- 1:19:19if that has upfold exists so if if it's
- 1:19:25a chewable value so it will internally
- 1:19:28be true actually if this is true then uh
- 1:19:33we don't need actually hover anymore but
- 1:19:35we can leave that but we're going to
- 1:19:38directly make the color blue 500 right
- 1:19:43so let's do like this and in else simply
- 1:19:47we don't add anything let's make on
- 1:19:49however it uh like a 600 let's do like
- 1:19:52this and in the downward button we do
- 1:19:55the same thing very similar thing
- 1:19:58however if the upvote equals false okay
- 1:20:03I don't want to type if not upvote
- 1:20:06because that's tricky null is also not
- 1:20:11has upvote so if the hazard for this
- 1:20:14null then this will be also satisfied
- 1:20:16that's why I want to explicitly check if
- 1:20:19it has upvote is equals false with three
- 1:20:23equality because
- 1:20:25right here we're going to have false so
- 1:20:28in this case I add the text blue 500
- 1:20:30right here otherwise we had an empty
- 1:20:32class let's change this into 600 let's
- 1:20:35save this reload the page
- 1:20:38and voila we see this upfold pattern
- 1:20:41blue if I Mouse over it slightly changes
- 1:20:44the color because it's uh now on Hover
- 1:20:46we have 600. if I click on the download
- 1:20:49then this button becomes blue so that's
- 1:20:52a perfect indicator for me as a user
- 1:20:56that I have once upvoted that particular
- 1:21:00article which is which is awesome now
- 1:21:03I'm going to do one small fix
- 1:21:06so right here we don't see the previous
- 1:21:08pattern but actually if we click next
- 1:21:11and keep clicking next finally we're
- 1:21:15going to reach the end where there are
- 1:21:17no more articles and in this case
- 1:21:20there will be a problem so in this view
- 1:21:23blade we check if the previous exists
- 1:21:25then we render the previous button
- 1:21:28and if it doesn't exist simply this is
- 1:21:31not rendered however we don't do the
- 1:21:33same check for the next button so as
- 1:21:36simple as that like let's copy this if
- 1:21:39statement and change this prev into next
- 1:21:43and then right here we need end if
- 1:21:47so we format the code and if the next
- 1:21:50exists we render that if it doesn't
- 1:21:52exist we don't render that and it's as
- 1:21:54simple as that now let's start working
- 1:21:56to save views for each article whenever
- 1:21:59user opens an article we're going to
- 1:22:01save that and probably also save a user
- 1:22:04ID maybe IP addresses as well as the
- 1:22:07user agent so we have a little bit of
- 1:22:09information from which location users
- 1:22:12are checking our posts as well as from
- 1:22:14which browsers they're actually doing
- 1:22:16this so it's going to be good good to
- 1:22:18save so we're going to create migration
- 1:22:20save post views and then in the admin
- 1:22:23panel we're going to display for each
- 1:22:24article how many views that article gets
- 1:22:27and later we can also Implement to sort
- 1:22:29the top particles or posts by their
- 1:22:34number of views right
- 1:22:36so I think it's going to be pretty
- 1:22:37interesting so I'm going to open
- 1:22:38phpstorm first I'm going to bring up the
- 1:22:42terminal and I'm going to create
- 1:22:43migration PHP artisan make I'm going to
- 1:22:48create model post to view and I'm going
- 1:22:50to generate migration as well now let's
- 1:22:52open create post migration
- 1:22:56not this one but create post create post
- 1:23:00views actually so we need to Define two
- 1:23:04columns right here so string
- 1:23:08uh one will be IP address and let's give
- 1:23:11it a length of 55. I'm going to Define
- 1:23:13also user agent let's give it a length
- 1:23:18of 205 I'm going to Define our foreign
- 1:23:22ID for post table according ID post ID
- 1:23:25that has constrained
- 1:23:30constrained on post table and I'm going
- 1:23:34to duplicate this basically right here
- 1:23:35in this constraint method you can
- 1:23:36specify the table name however if you
- 1:23:39don't specify it's gonna a lot of it
- 1:23:41will assume that there's a posts table
- 1:23:44based on the column name
- 1:23:46and we can specify here user ID as well
- 1:23:49but the user ID actually should be
- 1:23:51nullable because
- 1:23:52unauthorized users might also be
- 1:23:55checking articles right
- 1:23:57so I'm going to save these now let's
- 1:24:00open post view model and right here I'm
- 1:24:04going to define a fillable
- 1:24:07with these four columns so I'm gonna
- 1:24:11just copy them paste here
- 1:24:16let's
- 1:24:17save everything let's semicolon all
- 1:24:19right now we have modal and migration
- 1:24:21ready now I'm going to bring up the
- 1:24:23terminal and execute PHP Artisan migrate
- 1:24:27all right now we have this table ready
- 1:24:30and let's open
- 1:24:32post controller
- 1:24:36and we're going to check uh show method
- 1:24:39where we're going to see one specific
- 1:24:41post and right here we are going to
- 1:24:45maybe
- 1:24:47First Take request
- 1:24:50then down below from that request we are
- 1:24:54going to get currently authorized user
- 1:24:58and then we're gonna run host view
- 1:25:01create
- 1:25:03so we're going to create a postview
- 1:25:05record we're going to specify IP address
- 1:25:09and we're going to get these from
- 1:25:11request IP method we are going to
- 1:25:14specify user agent
- 1:25:17we get this from request
- 1:25:20user agent and we're going to specify
- 1:25:23also post ID
- 1:25:26which will be current post ID and user
- 1:25:31ID as well and that's going to be
- 1:25:33current a user
- 1:25:36but I'm going to use a question mark
- 1:25:37Arrow here because the user might be now
- 1:25:41and then specify ID right here so this
- 1:25:43will basically return null if the user
- 1:25:45is now
- 1:25:46and it's gonna it's not gonna throw an
- 1:25:49error so I save this and now let's open
- 1:25:52website and we are on specific article
- 1:25:55page and I'm just going to reload that
- 1:25:57page now let's check in the database in
- 1:26:03the post views table what do we have
- 1:26:05here so we have recorded
- 1:26:07and this is the API IP address and this
- 1:26:10is the IP of the docker container
- 1:26:12running and we have the user agent we
- 1:26:15have pulse ID user ID and dates of
- 1:26:17course if I try to log out or try to
- 1:26:20open the same article in incognito mode
- 1:26:23it's going to make a second record but
- 1:26:26right here we don't have user ID because
- 1:26:28we made this nullable and just like this
- 1:26:31we save like all the basic things we
- 1:26:35need about the user who is basically
- 1:26:37viewing the article and later we can
- 1:26:40suggest to the user based on its views
- 1:26:43which articles might be relevant for
- 1:26:46that user all right here's one
- 1:26:49additional uh thing which can be added
- 1:26:51into this application and I give you
- 1:26:53this as a challenge I'm not going to
- 1:26:55implement this in this video
- 1:26:57if I keep refreshing this page it's
- 1:27:00gonna make records in the post Fields
- 1:27:03table as many times you refresh all
- 1:27:06right and as a suggestion you can
- 1:27:09generate a random token and save this in
- 1:27:12the user's cookie and you can give this
- 1:27:14random token Associated a lifetime like
- 1:27:17one hour for example and you will assume
- 1:27:19that all views the specific user will
- 1:27:23make on this article in one hour will be
- 1:27:26considered as a single View and you are
- 1:27:29not going to make records in the post
- 1:27:31views table unless that one hour or
- 1:27:34whatever time period you specify the
- 1:27:37time period passes and that's good
- 1:27:39because if the user opens the article
- 1:27:41and for some reason decided to refresh
- 1:27:44it or just close and reopened it
- 1:27:46immediately so you're gonna make record
- 1:27:49multiple times
- 1:27:51okay you can assume that this is a
- 1:27:53single View
- 1:27:54but if the user checks that article like
- 1:27:57few hours later or like uh tomorrow then
- 1:28:01you can consider that this is a second
- 1:28:02View
- 1:28:03okay as I mentioned I'm not going to
- 1:28:05implement this but as a challenge I
- 1:28:07think it's really interesting and useful
- 1:28:09so I give this challenge to you and let
- 1:28:11me know in the comments section if any
- 1:28:13one of you will implement this challenge
- 1:28:15in this uh in this project all right I
- 1:28:18would love to know about this
- 1:28:21all right now we have that information
- 1:28:23it's time to bring that in the admin
- 1:28:26panel and display these probably above
- 1:28:28the
- 1:28:29um about this card to display number of
- 1:28:32views for that specific post also number
- 1:28:36of likes or the same as app folds and
- 1:28:39downloads because we have all that
- 1:28:41information in these like we just need
- 1:28:43to Output them okay to display that kind
- 1:28:45of information we need to create widgets
- 1:28:48in filament so I'm going to open
- 1:28:50filament PHP documentation and we can
- 1:28:52search for uh widgets somewhere
- 1:28:56let's search for widgets here we have
- 1:28:59that
- 1:29:00getting started okay so we need to
- 1:29:02create a widget we can specify also the
- 1:29:06resource and then we need to display
- 1:29:11that widget in the post view so let's
- 1:29:13start step by step so first I'm going to
- 1:29:15create the widget I'm going to copy this
- 1:29:17command and open uh PHP swarm I'm going
- 1:29:21to close everything let's bring up the
- 1:29:23terminal and execute uh phpr design make
- 1:29:26filament widget let's call this post uh
- 1:29:31post overview right
- 1:29:33okay we can specify your resource but I
- 1:29:37think we can leave this as it is right
- 1:29:39now
- 1:29:39uh
- 1:29:42let's hit the enter okay post overview
- 1:29:44was actually created let's open this
- 1:29:46widget
- 1:29:48post
- 1:29:49overview
- 1:29:51here we have it it also generated a
- 1:29:54blade file for that so we can open also
- 1:29:57post Dash overview which is the blade
- 1:30:00file Associated to that specific widget
- 1:30:03I'm going to type here hello from widget
- 1:30:06okay we created the widget but we are
- 1:30:09not using it yet let's go in the post
- 1:30:13view app filament resources and we have
- 1:30:18right here host resource inside there we
- 1:30:21have a view post and that view post has
- 1:30:25get a header get header widgets and
- 1:30:29inside that get header widgets we can
- 1:30:32check the appearing but it's returning
- 1:30:34an empty array so we can return our
- 1:30:37widget we should return our widget and
- 1:30:40that's going to be post overview widget
- 1:30:43class all right so now let's save this
- 1:30:48and open the admin panel and just reload
- 1:30:52the page and look at this so right here
- 1:30:54we see hello from widget so we are using
- 1:30:56already our widget
- 1:30:59I want this widget to be on full width
- 1:31:02by default it is
- 1:31:04um like uh with a half half size but I
- 1:31:07want this to be on full width and then
- 1:31:09create three inner cards
- 1:31:13um inside the actual blade so let me
- 1:31:16actually do this in this widget post
- 1:31:19overview
- 1:31:20I'm going to Define uh called column
- 1:31:24spun
- 1:31:26column spot we actually we can actually
- 1:31:28check what properties the parent class
- 1:31:30the widget class has so we have a couple
- 1:31:32of um a couple of properties right here
- 1:31:34one of them is called span and I'm going
- 1:31:36to specify the column
- 1:31:38spawn to be actually three okay so let's
- 1:31:42save these and reload and now we see
- 1:31:44this to be on a full full width
- 1:31:48and we need also some sort of a data
- 1:31:51which needs to be passed to the Views to
- 1:31:54check this impairment again so we see
- 1:31:58this parent widget basically is a pure
- 1:32:01Live Wire component as you can see it
- 1:32:05extends for Livewire component so it has
- 1:32:09somewhere render method it renders our
- 1:32:12view past View and it passes get a view
- 1:32:15data right so this get view data is
- 1:32:19empty at the moment but we can
- 1:32:22we can override that get a view data
- 1:32:26function and return the data we need to
- 1:32:30be passed to the Views so we need three
- 1:32:34main things to be positive views like a
- 1:32:37view count
- 1:32:38number of views that specific post has
- 1:32:42uh we are going to pass let's let me
- 1:32:45leave empty right now we're going to
- 1:32:47pass upvotes number of upvotes
- 1:32:50and we're going to pass down volts
- 1:32:54all right
- 1:32:56let's start implementing from view uh
- 1:32:59view count so from post view we are
- 1:33:03gonna write aware
- 1:33:05and when to specify post ID
- 1:33:08equals
- 1:33:11to some post ID and that post ID
- 1:33:14basically can be taken from the record
- 1:33:18of this widget because we are using this
- 1:33:21widget inside view post
- 1:33:24right here that view post is for one
- 1:33:29specific post
- 1:33:31and we can use record
- 1:33:34we can use this record here so not sure
- 1:33:38if this is declared right here record I
- 1:33:41think this is not declared but it is
- 1:33:43written in the documentation that we can
- 1:33:45access that this record
- 1:33:47This Record
- 1:33:51and then obviously we can take the ID
- 1:33:54I'm going to collapse the left side so
- 1:33:56I'm going to take ID from here and then
- 1:33:59let's execute count on that okay view
- 1:34:02count
- 1:34:03let's save this and check if this works
- 1:34:06so far so view count variable needs to
- 1:34:09be available in the post overview so
- 1:34:12hello from widget and let's output view
- 1:34:14count with dollar sign obviously so we
- 1:34:17save this and reload the page
- 1:34:20and let's have a look record uh
- 1:34:23property record not found on component
- 1:34:26let's check post overview all right this
- 1:34:29is because we need to also Define this
- 1:34:32record so that's going to be public
- 1:34:35model record
- 1:34:39to be null but we also need to specify
- 1:34:41here question mark because uh because
- 1:34:44this is now by default in the question
- 1:34:46mark is necessary here let's actually
- 1:34:48import the eloquent model
- 1:34:51here we have that and whenever we Define
- 1:34:54this now we should not have this error
- 1:34:56anymore now look at this now we have
- 1:34:58number of views on that specific post
- 1:35:03that is perfect okay in the same way
- 1:35:06let's do Up full downloads
- 1:35:09avoid download where we specify
- 1:35:13post ID
- 1:35:15equals This Record ID
- 1:35:20and we call also another we are
- 1:35:24is upvote
- 1:35:26equals one and finally we call count
- 1:35:31like this and let's
- 1:35:34let me grab this and simply we're going
- 1:35:37to change
- 1:35:38is upvote equals zero and let's change
- 1:35:42this into integer or true or false we
- 1:35:45can even use true or false or one or
- 1:35:47zero as integers so I save this now
- 1:35:50let's print those two variables as well
- 1:35:53number of upfolds here
- 1:35:56and number of down votes here so here we
- 1:36:01go let's reload the page we see one up
- 1:36:04vote and zero download if I go on post
- 1:36:07and click on download button instead and
- 1:36:10reload now we see Zero upvote and one
- 1:36:13download okay now it's time to Simply
- 1:36:16render this content nicely in this area
- 1:36:22I'm going to open displayed file and
- 1:36:25let's specify the main widget to have
- 1:36:28the following CSS classes like let's
- 1:36:31give it agreed and grid columns three
- 1:36:35and let's give it also get three okay
- 1:36:38inside there I'm gonna have three cards
- 1:36:41so I'm going to duplicate this three
- 1:36:44times and if I save this and have a look
- 1:36:46we already see nice three cards right
- 1:36:48with equal width and now let's define in
- 1:36:53the first one we need to display view
- 1:36:55count
- 1:36:56uh let's use also like H2 to actually
- 1:37:00Define what information we have this in
- 1:37:02this card like views and let's give it
- 1:37:04classes like text large
- 1:37:08um above small let's give it text extra
- 1:37:11large let's give it font bold let's give
- 1:37:14it uh tracking light the following
- 1:37:18classes and down below let's create one
- 1:37:21div inside there let's give this div
- 1:37:24Flex because I want to display icon as
- 1:37:26well and give two in between and now
- 1:37:29here we need the some kind of eye icon
- 1:37:32and then we need view count
- 1:37:36right so let's open now hero icons
- 1:37:40and let's grab
- 1:37:43I icon here
- 1:37:46and let's paste right here save this and
- 1:37:51have a look
- 1:37:52okay views and this is 19 number of
- 1:37:56views that's perfect now let's move on
- 1:37:58the second one and we already have this
- 1:38:01kind of template of the card so why
- 1:38:04don't we delete the other cards and
- 1:38:06simply duplicate this because we all
- 1:38:08have all the CSS and right here we need
- 1:38:11to display up folds we want to obviously
- 1:38:14change this SVG so we can look for
- 1:38:17thumbs up
- 1:38:19called psvg
- 1:38:21paste here
- 1:38:24that is up folds by the way that should
- 1:38:26be down volts the last one should be
- 1:38:29down volts
- 1:38:32and the other one should be upvotes and
- 1:38:36my copied SVG will be for up folds and
- 1:38:40let's also output the variable up folds
- 1:38:43here this is downloads and now let's
- 1:38:45copy SVG for downloads download votes
- 1:38:48I'm gonna format the code oops
- 1:38:51and here we have 1000 volts okay and
- 1:38:54here's the overview now we have three
- 1:38:56cards the first one displays views and
- 1:38:59this is the the whole card let's
- 1:39:02collapse this second displays up folds
- 1:39:05and here we have the variable for
- 1:39:06upvotes and the third one is for down
- 1:39:09volts perfect so if I save this and now
- 1:39:13reload admin panel we see views outputs
- 1:39:16and down volts and let's just click on
- 1:39:19thumbs up here and this one obviously
- 1:39:22changes okay I think that's perfect now
- 1:39:25let's make categories in posts
- 1:39:27searchable in the admin panel because if
- 1:39:30you have more posts it's going to be
- 1:39:32hard to find your desired post so let's
- 1:39:35open
- 1:39:36well it's open let's close everything
- 1:39:38and open
- 1:39:41um oh it's called the list we need to
- 1:39:44open
- 1:39:45pulse resource and here we have tables
- 1:39:49and forms information
- 1:39:52so we don't care about the form at the
- 1:39:55moment we care about the table and in
- 1:39:57this table I'm going to specify that the
- 1:40:00title is basically searchable field and
- 1:40:03whenever you do this
- 1:40:05in the admin panel you will see this
- 1:40:07search box right here and then we can
- 1:40:10search for JavaScript and here we go we
- 1:40:13can search for lorem and we don't find
- 1:40:15anything we can search for Alice
- 1:40:20and here we find all Alice keywords
- 1:40:24mentioned in the title and I think
- 1:40:25that's perfect
- 1:40:27now let's do the same thing on
- 1:40:29categories I'm going to open
- 1:40:32category resource
- 1:40:34let's scroll down below on the title and
- 1:40:37specify here searchable
- 1:40:39[Music]
- 1:40:41below the page and we see and we can
- 1:40:42search for laravel here we find it
- 1:40:47okay that's good it searches inside the
- 1:40:50title for categories as well as for
- 1:40:51posts however if you open posts and we
- 1:40:54want to search some text inside body as
- 1:40:58well let me edit this and in the body
- 1:41:00right here I'm gonna add like a zura
- 1:41:03keyword
- 1:41:04okay so if I save this and go in the
- 1:41:06post and then try to search zura I
- 1:41:08couldn't find that because this search
- 1:41:10is only inside title right if I specify
- 1:41:13zura in title obviously it's going to
- 1:41:15find but this is not what we want we
- 1:41:17want to search in the body as well we
- 1:41:20can specify to this searchable method
- 1:41:22array of attributes it needs to search
- 1:41:26in
- 1:41:28in this case we will specify title in
- 1:41:30body
- 1:41:31in this post resource so I save this and
- 1:41:34now if I type 0 right here it's going to
- 1:41:37find this because it searches now inside
- 1:41:39body as well
- 1:41:40I think that's awesome
- 1:41:42the searchable even has if we just click
- 1:41:45on this it has a couple of options right
- 1:41:47here you can even specify whether the
- 1:41:50search is for individual column or This
- 1:41:54Global search like if you specify here
- 1:41:56that this is for is
- 1:41:59is individual uh actually let me let me
- 1:42:03do like this is individual and we
- 1:42:06specify true here
- 1:42:08this means the following we are gonna
- 1:42:11see this individual search field in that
- 1:42:15specific column
- 1:42:17and we can obviously add additional
- 1:42:19searchable columns right here like a
- 1:42:22filter by status whether it's an active
- 1:42:25or not we can filter by publish date and
- 1:42:29so on
- 1:42:31okay in this case I'd rather to have a
- 1:42:33single search because I don't have that
- 1:42:35much cons right there so I'm going to
- 1:42:38specify searchable with the title in
- 1:42:40body and I can also specify sortable if
- 1:42:44I want so
- 1:42:45so if I just follow the page I see that
- 1:42:47the title is now sortable and then click
- 1:42:49on this and sort uh by the actual title
- 1:42:52and the sortable is I think very useful
- 1:42:55so we can specify this on publish that
- 1:42:58as well and maybe on active as well
- 1:43:02so if I save and reload we see that we
- 1:43:04can sort burst only deactivated
- 1:43:08posts and then actives one and if we
- 1:43:10click on the publish date we can do
- 1:43:12something similar right here
- 1:43:16I'm going to add this sortable to
- 1:43:18category Resource as well on title and
- 1:43:23probably on updated it as well
- 1:43:26now I'm going to add one useful thing to
- 1:43:28every post whether you're in a post
- 1:43:31inner page or in list as well and that's
- 1:43:34going to be estimated read time in a
- 1:43:37human readable format and also number of
- 1:43:40words for that article so that when
- 1:43:43you're looking through the blog website
- 1:43:44you immediately know if this is not too
- 1:43:48long probably you want to click it and
- 1:43:50just read it okay if it's like five
- 1:43:51minute two minutes article so I think
- 1:43:54that's that's really handy and useful
- 1:43:57feature so let's actually uh open uh
- 1:44:00post model I'm going to do this in post
- 1:44:02model and I'm going to create a custom
- 1:44:04attribute where's the post model here I
- 1:44:08have it
- 1:44:09okay let's close to the left side and
- 1:44:12maybe at the very bottom I'm going to
- 1:44:14create a public function human read time
- 1:44:20and that's going to return custom
- 1:44:23attribute from illuminate database
- 1:44:25eloquent class attributes so we'll
- 1:44:28return new attribute
- 1:44:33and we are going to Define only getter
- 1:44:36for this
- 1:44:38we get value and actual attribute here
- 1:44:43and now what do we need to return from
- 1:44:46here so we're going to return number of
- 1:44:48minutes to read that article that post
- 1:44:52as well as a number of words so let's
- 1:44:56start by counting number of words and
- 1:44:59that will be using Str facade
- 1:45:02uh
- 1:45:04okay so it's your helper we're going to
- 1:45:06execute words method here and
- 1:45:10actually we need to specify a word count
- 1:45:13and let's specify
- 1:45:15the body and it's going to be
- 1:45:18from attributes let's call this
- 1:45:21attributes in plural form from
- 1:45:24attributes to get the body but that body
- 1:45:28will contain HTML tags as well so let's
- 1:45:31run strip tags endbody
- 1:45:35okay so we have number of words
- 1:45:39how to define a reading minutes for that
- 1:45:42specific
- 1:45:43words like to take an estimate average
- 1:45:48number of words per minute it is about
- 1:45:52like a 200 words so we call sale method
- 1:45:59divide number of words on 200 and just
- 1:46:04like this we have minutes
- 1:46:07and then we're going to return from here
- 1:46:09minutes but we are going to also specify
- 1:46:13like a mean right here as a string but
- 1:46:18based on whether this means is a one or
- 1:46:21two we either need mean or means or like
- 1:46:25minutes whatever we decide so in this
- 1:46:27case I'm going to wrap the word mean and
- 1:46:33then specify that I want this to be
- 1:46:35converted into plural based on mints
- 1:46:39values and just like this we have number
- 1:46:43of means I'm going to leave a number of
- 1:46:45words
- 1:46:46unimplemented at the moment and let's
- 1:46:49open post item blade and probably here
- 1:46:54next to the get formatted date we are
- 1:46:57going to Output post and whatever is the
- 1:47:01name like human read time in a camel
- 1:47:04case we need to convert this into
- 1:47:05underscore format human 1 read time so I
- 1:47:10save this and reload the page and we see
- 1:47:13five means here five minutes here all of
- 1:47:16them probably will be five minutes
- 1:47:17except the first one this is just one
- 1:47:19mint right so that's excellent now let's
- 1:47:23go in the post and append right here
- 1:47:26number of words as well like comma
- 1:47:29and then
- 1:47:31words
- 1:47:32space
- 1:47:35let's wrap
- 1:47:38oops
- 1:47:40words in called plural on that
- 1:47:44on words
- 1:47:46here we go we format everything and
- 1:47:49reload the page and we see one minute 90
- 1:47:51words like five minutes nine hundred
- 1:47:54something words okay and we'll see five
- 1:47:57minutes and on the others basically will
- 1:47:59have roughly the same number of words
- 1:48:01but if we edit the article which is
- 1:48:05created by us and simply copy let's
- 1:48:08remove the Zero by the way and copy and
- 1:48:11paste these multiple times and click
- 1:48:13save changes reload the page at the very
- 1:48:16top we see three minutes 200 450 words
- 1:48:19so this is it and we can output this
- 1:48:22information on the inner page as well so
- 1:48:24I'm going to open view dot blade
- 1:48:29PHP this one and scroll down below and
- 1:48:34right here we output
- 1:48:37post human read time
- 1:48:41so we save reload
- 1:48:45and here we see that
- 1:48:47perfect
- 1:48:49now I'm going to start working on home
- 1:48:51page and I'm going to define a couple of
- 1:48:54sections on the home page just modify
- 1:48:56that
- 1:48:57to make it more like a home page design
- 1:49:00where we're going to have an overview of
- 1:49:03our blog blog website like I'm going to
- 1:49:06display what is the latest post I'm
- 1:49:08going to show the most popular three
- 1:49:10articles actually let's open post
- 1:49:14controller or maybe we can start from
- 1:49:16web PHP and have a look so we have this
- 1:49:19post controller index method which is
- 1:49:22actually rendering the home so I think
- 1:49:24we should rename this method to home
- 1:49:26from here and here as well and at the
- 1:49:29moment we are just rendering
- 1:49:3110 posts through the pagination so I'm
- 1:49:36going to completely remove this
- 1:49:39and I'm going to Define which is the
- 1:49:41latest post so we want to show latest
- 1:49:43post I'm going to show the most popular
- 1:49:48uh three posts based on upvotes I'm
- 1:49:53going to show recommended
- 1:49:57posts based on user user app folds if
- 1:50:03the user is authorized okay so if
- 1:50:06authorized however if the user is not
- 1:50:08authorized
- 1:50:11um let's not authorized let's define
- 1:50:16um
- 1:50:17popular
- 1:50:19posts based on views
- 1:50:24so and let's fix the typo
- 1:50:28and we are gonna also show top
- 1:50:31categories
- 1:50:34or maybe like a recent
- 1:50:37recent
- 1:50:38categories with their latest
- 1:50:44posts okay so I want to have these four
- 1:50:48main sections
- 1:50:50um on my on my website
- 1:50:54and let's open
- 1:50:55a home blade PHP and we are going to
- 1:51:00remove sidebar and everything and I'm
- 1:51:02going to define those
- 1:51:04um four four sections in the following
- 1:51:07way so we have this container and inside
- 1:51:09there I'm going to Define one div and
- 1:51:12that's going to be the header section
- 1:51:14inside that div I will have
- 1:51:17latest post section and I'm gonna have
- 1:51:23um
- 1:51:25popular
- 1:51:26posts popular
- 1:51:28three posts okay so that's going to be
- 1:51:32the second div and this will have let's
- 1:51:35give it proper CSS classes this will
- 1:51:37have a grid let's give it grid calls one
- 1:51:41but above medium screen
- 1:51:43let's give it greed calls three maybe
- 1:51:49let's give it also Gib four
- 1:51:52okay we should put this
- 1:51:55in a comment
- 1:51:58like this uh
- 1:52:02hold on okay like this
- 1:52:06we need
- 1:52:09comment here as well
- 1:52:12popular three posts okay and at the very
- 1:52:16bottom I'm gonna have two more div
- 1:52:17elements
- 1:52:19and this one will be recommended
- 1:52:25posts
- 1:52:30and this one will be latest articles
- 1:52:34um sorry latest categories
- 1:52:40like this
- 1:52:42okay perfect now we need to feel those
- 1:52:45gaps if I just type dummy text latest
- 1:52:48post here maybe we can Define also
- 1:52:51heading of that section like H2 let's
- 1:52:54give it proper CSS classes like I'm
- 1:52:57going to give it a text large and above
- 1:52:59small let's give it text a text EXO
- 1:53:02let's also give it a font bold and give
- 1:53:07it text blue 500 give it uppercase
- 1:53:11everything
- 1:53:12let's give it also padding button one
- 1:53:15and Border a bottom two I'm going to
- 1:53:18give it also border blue
- 1:53:21um Order Blue 500 okay and maybe small
- 1:53:25margin as well
- 1:53:27and inside there I'm going to type
- 1:53:29latest
- 1:53:30post now if I save this and have a look
- 1:53:33we have a nerve and the compact we don't
- 1:53:37pass anything so let's remove compact
- 1:53:40completely I say this reload the page
- 1:53:43and we see this latest post now that's
- 1:53:47good however this latest post I want to
- 1:53:49give it a call span 2. I want this to
- 1:53:53take the two third of the entire screen
- 1:53:57and then this one will have one third
- 1:54:01okay
- 1:54:02um
- 1:54:03I think this is good
- 1:54:05create grid calls one above
- 1:54:11why doesn't this take the
- 1:54:13to Third
- 1:54:17because this doesn't have full width
- 1:54:20and I guess this is the reason
- 1:54:24uh this one has Flex aha so we we need
- 1:54:27to remove this Flex it shouldn't be Flex
- 1:54:30okay so now this takes two thirds I
- 1:54:32think the container with for the home
- 1:54:34page is a little bit too large so I'm
- 1:54:36going to reduce it Max with maybe like a
- 1:54:393XL let's see how it goes
- 1:54:43um okay let's let's try let's start with
- 1:54:45this and have a look
- 1:54:47okay now we have this latest post I can
- 1:54:49copy this title and that will be popular
- 1:54:53posts
- 1:54:55uh here we will have
- 1:54:58recommended
- 1:55:01recommended posts and down below we have
- 1:55:04latest categories
- 1:55:08uh recent
- 1:55:10recent categories maybe or recent posts
- 1:55:14okay let's give it recent categories
- 1:55:18okay so we save this and we have uh four
- 1:55:22four sections as we as we defined now we
- 1:55:25need to pass proper variables to fill
- 1:55:28those sections right so now we need to
- 1:55:30work inside the post controller and
- 1:55:33let's start with the latest post which
- 1:55:35is slightly easier compared to others
- 1:55:38from post we are gonna uh query where
- 1:55:42active
- 1:55:44so first flag needs it needs to be
- 1:55:47active specify one as an integer we need
- 1:55:51to also Define uh where date
- 1:55:55published
- 1:55:58eight needs to be
- 1:56:01um
- 1:56:02less than
- 1:56:04carbon now
- 1:56:07okay so it needs to be published by date
- 1:56:09and Status means to be active as well so
- 1:56:12let's order by
- 1:56:14order by published
- 1:56:17it descending
- 1:56:21and I want to get limit one
- 1:56:25and then first
- 1:56:29okay I think I have everything correctly
- 1:56:31so this latest post now can be passed to
- 1:56:35view
- 1:56:37like this so now let's print if we have
- 1:56:40latest post here
- 1:56:43latest post
- 1:56:46save that
- 1:56:47and I do have this here and I'm going to
- 1:56:50actually use existing
- 1:56:52component X post item component and
- 1:56:56specify here post to be latest post
- 1:57:01okay
- 1:57:03save this and here is the latest post
- 1:57:06information on the home page awesome now
- 1:57:10let's move on the popular posts
- 1:57:12so how should we Define the popularity
- 1:57:16of the post we need to do this based on
- 1:57:19number of upfolds so let me create a
- 1:57:22variable first popular posts equals post
- 1:57:26uh let's run query
- 1:57:30let's join these we need to join this
- 1:57:33into upvote downloads table up vote down
- 1:57:37volts
- 1:57:39where posts ID
- 1:57:42equals to upvote
- 1:57:45down votes
- 1:57:47dot post underscore ID
- 1:57:51okay so we join this now we need to
- 1:57:54select
- 1:57:56we select uh we're doing it so we need
- 1:57:59posts everything from Posts
- 1:58:02let's also select number of upfolds for
- 1:58:08that post because then we need to order
- 1:58:11by number of upvotes and if we don't
- 1:58:14select put this in the select we won't
- 1:58:17be able to order by by that so in this
- 1:58:21case I'm going to use DB roll and
- 1:58:24specify here
- 1:58:25account
- 1:58:29upvote down votes ID and let's give it
- 1:58:32an alias is
- 1:58:34upfold count right so we need to add
- 1:58:40additional wear here
- 1:58:41we just don't want to query every
- 1:58:44everything from upvote downloads because
- 1:58:46there's a flag is upvote needs to be
- 1:58:50equal one we don't want those up for
- 1:58:54download records which has download
- 1:58:56right
- 1:58:59so in the weird I'm going to specify a
- 1:59:01function which will be query
- 1:59:07and on that query I'm going to run where
- 1:59:12upvote down volts
- 1:59:15is
- 1:59:17upvote
- 1:59:19equals
- 1:59:21one
- 1:59:22okay
- 1:59:24okay perfect let's add additional wear
- 1:59:28so we want those posts we basically need
- 1:59:32to grab this no this part because we
- 1:59:37want to get only those posts which has
- 1:59:40active one and published it is in the
- 1:59:43past
- 1:59:44and we want to order by this
- 1:59:48order by descending by the following the
- 1:59:53following name like a count of upvote
- 1:59:56down votes right so we specify upvote
- 1:59:59download here we also need to run Group
- 2:00:02by posts ID we don't want duplicate the
- 2:00:06records that's why we need to run Group
- 2:00:08by and finally we need to limit this to
- 2:00:11get three records and let's call get
- 2:00:14okay if I don't make any mistake we
- 2:00:17should have popular posts by their
- 2:00:19number of upfolds
- 2:00:22okay let's pass this popular posts right
- 2:00:25here
- 2:00:26let's go in the home blade and we have
- 2:00:29popular posts here and let's output that
- 2:00:32let's have a look okay we don't have any
- 2:00:35error it probably means that we have
- 2:00:37successfully implemented that so now we
- 2:00:40need to iterate over our popular posts
- 2:00:43for each popular posts is post
- 2:00:48let's create a div let's give this Steve
- 2:00:51greed greed
- 2:00:54calls
- 2:00:56uh maybe four let's give it skip two
- 2:00:59inside there I'm going to create one div
- 2:01:01which is going to be the image wrapper
- 2:01:03so in the source we're going to specify
- 2:01:06post get thumbnail
- 2:01:13let's specify alt to be post
- 2:01:16title
- 2:01:18like this and let's specify second div
- 2:01:22inside there we're going to have maybe
- 2:01:24inside H3 post title
- 2:01:28and we need like a short description
- 2:01:31like we have it in the post item so we
- 2:01:34need to use the same method short body
- 2:01:37short body here we have this method okay
- 2:01:41let's
- 2:01:44let's print it
- 2:01:46post
- 2:01:48uh short body
- 2:01:50I have feeling that this short body will
- 2:01:53be too large for that section
- 2:01:56let's have a look
- 2:01:57the second div should have called span
- 2:02:02of three so basically we are splitting
- 2:02:04the entire width on four equal spaces
- 2:02:07then this image will have one part in
- 2:02:09the description and title and the short
- 2:02:11body will have three part so if I save
- 2:02:14everything it should be like this okay
- 2:02:17an image and the title in the body this
- 2:02:20body needs to have smaller fonts so
- 2:02:23let's specify text SM
- 2:02:26okay that's good uh let's give it also
- 2:02:29text
- 2:02:31semi-bold
- 2:02:34okay I think that's good but again as I
- 2:02:38mentioned this description is too large
- 2:02:39so inside short body I'm gonna specify
- 2:02:43I'm gonna Define uh like Words variable
- 2:02:47which by default will be 30. so that's
- 2:02:49that's a good lesson to learn so I'm
- 2:02:52using this short body from somewhere
- 2:02:53else I want to modify this short body
- 2:02:56arguments so that it doesn't break other
- 2:02:59place
- 2:03:00if I just make this argument required
- 2:03:04like words here and then I specify words
- 2:03:07here it's going to break the other
- 2:03:09places because other places where I use
- 2:03:10this short body we don't pass these
- 2:03:13words variable so we need to make these
- 2:03:16words optional so that by default it
- 2:03:19still is 30 and from other places if we
- 2:03:22are using this short body we don't pass
- 2:03:24this 30 and we don't have any problems
- 2:03:27but in this case on home page I want to
- 2:03:30pass 10 instead of 30 10 words so now
- 2:03:35this is more liked
- 2:03:38okay that's perfect however on this
- 2:03:41container I'm going to give it like a
- 2:03:43slight padding top adding top Maybe two
- 2:03:49so this image is moved down and that's
- 2:03:52it you have it
- 2:03:55however
- 2:03:56why we don't see more than one post here
- 2:04:05okay don't we have other posts let's
- 2:04:09check the post controller
- 2:04:12so we joined this I put downwards
- 2:04:18okay I see the reason so because we
- 2:04:21write the left join here
- 2:04:23it basically means that
- 2:04:26upfo download might not even exist
- 2:04:29um on the post
- 2:04:31and in this case we in the we are close
- 2:04:33we have this now is upvote needs to be
- 2:04:37equal always one and that's basically
- 2:04:39what causes the problem so here we can
- 2:04:42specify
- 2:04:43we are
- 2:04:45we are null to be more specific so
- 2:04:49upvote download
- 2:04:51specify up vote down volts
- 2:04:56is up fold needs to be either null
- 2:05:00or its value needs to be one it will be
- 2:05:03now whenever the left join doesn't
- 2:05:06return any any anything basically so
- 2:05:08whenever the post doesn't have upload
- 2:05:10downwards this will be null however if
- 2:05:13there exists a record for the
- 2:05:16corresponding post inside app vote
- 2:05:18downloads table
- 2:05:20this will return record and then the
- 2:05:22value needs to be won so if I save this
- 2:05:24now and reload the page
- 2:05:29they break anything
- 2:05:34okay we don't see anything
- 2:05:39oops here we need or where
- 2:05:42the upflow down which needs to be now or
- 2:05:45it needs to be one so I think that it is
- 2:05:49here we go so now we have
- 2:05:51three articles right here because we
- 2:05:55basically are limiting to three so we
- 2:05:57have three articles image title let's
- 2:06:00make title
- 2:06:01a little bit
- 2:06:03like a maybe bold
- 2:06:06to stand out from from anything else
- 2:06:10um
- 2:06:12okay let's give it
- 2:06:14uppercase Maybe
- 2:06:18no I don't like text bold white Expo
- 2:06:23doesn't work
- 2:06:24as I expected
- 2:06:29is their text extra small
- 2:06:32on buddy okay if we reduce the body we
- 2:06:35can reduce this one as well so we give
- 2:06:37it a text small uppercase Maybe
- 2:06:41okay not paid
- 2:06:43and we can give this one also no wrap
- 2:06:47text no wrap or white space no wrap
- 2:06:51um
- 2:06:53okay I'm gonna look for this talwind CSS
- 2:06:57a white space no wrap
- 2:07:03okay I think this is the class so let's
- 2:07:06specify this here
- 2:07:10it goes on full width and
- 2:07:16let's search for also Talon CSS text
- 2:07:21overflow
- 2:07:23ellipsis
- 2:07:27okay I want to show simply three dots
- 2:07:30there
- 2:07:31truncate does that class
- 2:07:34do what we want let's see
- 2:07:37okay yeah this does what we want
- 2:07:40I'm gonna add extra margin margin bottom
- 2:07:43three between each posts
- 2:07:48like these maybe even
- 2:07:50four
- 2:07:53okay so the latest post and the latest
- 2:07:56popular post like a three post
- 2:07:59well I think that
- 2:08:01um
- 2:08:02the
- 2:08:04the text size is too small compared to
- 2:08:08the left one so we should probably even
- 2:08:10reduce the left side but in this case we
- 2:08:13are using the uh same uh host item
- 2:08:17component what we have on the other
- 2:08:19pages so changing this will affect the
- 2:08:22other Pages as well so I don't want to
- 2:08:23spend too much time on design part again
- 2:08:26like we can simply increase the number
- 2:08:29of items into five here
- 2:08:33um reload the page and again if we add
- 2:08:35extra extra things like
- 2:08:40well let me show you like we have this
- 2:08:44by who who is the owner of this article
- 2:08:48basically or what's the read time of
- 2:08:51this article or what are the categories
- 2:08:54so let's grab the categories section in
- 2:08:57the home page and let's put this below
- 2:09:01title here maybe
- 2:09:04so I save this here we see now
- 2:09:06JavaScript is a category we can slightly
- 2:09:10change instead of text blue 700 let's
- 2:09:14give it PG blue 700 and give it text
- 2:09:18white and padding padding two
- 2:09:22something like this
- 2:09:25padding one and rounded and instead of
- 2:09:31700 let's give it 500.
- 2:09:34okay so we create this small small tags
- 2:09:37let's give it text excess extra small
- 2:09:45okay so those are the tags
- 2:09:47for that specific
- 2:09:51of that specific article
- 2:09:56and that section needs to have like a
- 2:10:00margin button as well
- 2:10:04okay
- 2:10:06we can this div is rendered now for
- 2:10:09every
- 2:10:10for every article
- 2:10:12even though there are no categories
- 2:10:15because we don't have this in the if
- 2:10:16statement we can actually wrap this
- 2:10:19if the post categories is not empty then
- 2:10:23render this part which I'm not going to
- 2:10:25do you can do it if you want
- 2:10:29I'm going to reduce this part adding tab
- 2:10:32on the image so the image needs to be
- 2:10:34moved a little bit up
- 2:10:37and I can finally
- 2:10:39give a slight increase on the container
- 2:10:42width okay so this is it
- 2:10:45we have the latest post
- 2:10:47we have the popular posts we can
- 2:10:50increase the
- 2:10:52Gap right here up to eight Maybe
- 2:10:58that's that's good that's good and of
- 2:11:01course whenever we click on one of the
- 2:11:02posts when it needs to open the inner
- 2:11:04page so if we go in the popular post
- 2:11:07section
- 2:11:08uh here maybe on the image if I change
- 2:11:12this into a and if I change this
- 2:11:16if I wrap this
- 2:11:19into a as well
- 2:11:21and give this one href roads
- 2:11:27um I'm going to check in the rotor here
- 2:11:30we have this View and I need to pass
- 2:11:32post so View and post
- 2:11:36and do the same thing
- 2:11:40here
- 2:11:41so I need
- 2:11:43you and post I save and reload the page
- 2:11:47and I see when I click on this it opens
- 2:11:49the article click on this it opens the
- 2:11:51article it also keeps track which
- 2:11:53articles I opened
- 2:11:56not too bad not too bad let's put extra
- 2:12:00button like we have on the post item
- 2:12:03continue reading button
- 2:12:06and by the way it's the the continue
- 2:12:07reading button doesn't have proper link
- 2:12:10here which we can specify
- 2:12:14like oops
- 2:12:16like
- 2:12:18we did
- 2:12:19here I'm going to take this href
- 2:12:22specify here
- 2:12:26now if I click this continue reading it
- 2:12:29opens the inner page and I'm going to
- 2:12:32get this continue reading and put this
- 2:12:35here
- 2:12:39okay the text size needs to be
- 2:12:44text
- 2:12:46s
- 2:12:48extra small
- 2:12:50and the arrow
- 2:12:54yeah here here it uses font awesome
- 2:12:57Arrow which is fine
- 2:13:01okay now we are more like uh filling all
- 2:13:05the missing vertical hate compared to
- 2:13:08the left latest Post article which is
- 2:13:12fine
- 2:13:12okay and we have these links also and
- 2:13:16clicking on the image everything is
- 2:13:17working fine okay so we have this now
- 2:13:19two sections of home page active and
- 2:13:21ready let's move on to the next one
- 2:13:23which is recommended posts
- 2:13:26I'm going to open post controller and
- 2:13:28let's now Define the I think this is
- 2:13:31very interesting part
- 2:13:33so first let's get the authorized user
- 2:13:35information I'm going to get this from
- 2:13:37auth user then I'm going to write an if
- 2:13:41statement if the user exists it means
- 2:13:44that we're going to write a different
- 2:13:45query if the user doesn't exist we are
- 2:13:48going to write different query the else
- 2:13:50part is slightly easier so I'm going to
- 2:13:54actually do this and it's very similar
- 2:13:56to popular posts so I'm going to get
- 2:13:59this however I'm going to modify a few
- 2:14:01things
- 2:14:03let's give it also name different name
- 2:14:05recommended
- 2:14:07posts so we start query from Posts we
- 2:14:11left join on poster views
- 2:14:15post ID equals to post views post ID
- 2:14:18then we select posts and post views ID
- 2:14:23is view count let's call this view count
- 2:14:29then we write additional wear
- 2:14:31uh this wheel basically is not necessary
- 2:14:34because
- 2:14:35if there is a record in the post views
- 2:14:37table
- 2:14:38it's just it just needs to be counted
- 2:14:40okay we don't care about anything else
- 2:14:42so I can remove this
- 2:14:44we are activities to be won and
- 2:14:46published it needs to be in the past
- 2:14:47that's totally necessary and then we
- 2:14:50have order by descending in this case
- 2:14:52order by view count
- 2:14:54then we have group by post ID and limit
- 2:14:585 and get so we have this recommended
- 2:15:00post we can already pass that that's for
- 2:15:04non-authorized users
- 2:15:06now let's define it for authorized users
- 2:15:09which is slightly more challenging in my
- 2:15:12opinion
- 2:15:14so first I'm going to define the main
- 2:15:16query and I'm going to Define sub query
- 2:15:18as well on which I want to make a join
- 2:15:22so the idea is the following I want
- 2:15:26to query posts which are in the same
- 2:15:30category
- 2:15:32on which in which I already upvoted some
- 2:15:36of the posts so if I uploaded for
- 2:15:38example a post from the JavaScript
- 2:15:41category in my recommended post I will
- 2:15:44see another post from the JavaScript
- 2:15:46category okay this is what I'm going to
- 2:15:49do
- 2:15:50so let's start
- 2:15:52defining recommended posts equals posts
- 2:15:57query
- 2:15:59we need a left join on
- 2:16:01left joint on category post
- 2:16:06let's give it to nalius as well like is
- 2:16:08in category
- 2:16:10both SIDS CP Maybe
- 2:16:12we are posts ID
- 2:16:14equals to CP
- 2:16:18post ID
- 2:16:22okay I'm gonna write another lift join
- 2:16:25but in this case I want a sub-qa
- 2:16:28and that sub query um let's let's call
- 2:16:31this um like left join
- 2:16:34there's going to be some sort of string
- 2:16:36I'm going to use that left join at the
- 2:16:39moment
- 2:16:41I'm going to also Define extraware
- 2:16:44clause here
- 2:16:46well I think we should first Define what
- 2:16:49should be this left join so that's going
- 2:16:52to be select
- 2:16:54from
- 2:16:56upvote down volts
- 2:16:59down volts
- 2:17:01we're going to join into category post
- 2:17:06as CPU on upfold downloads
- 2:17:12host ID
- 2:17:14equals CP let's move this down
- 2:17:18as CP
- 2:17:20host ID so we are selecting from upload
- 2:17:24downloads then join to category post and
- 2:17:27finally we're going to query we need
- 2:17:30extra wear closes here but finally we're
- 2:17:32going to query category ID from this
- 2:17:35category post category ID and we need a
- 2:17:40post ID
- 2:17:42and let's give extra weird we are upvote
- 2:17:48down votes
- 2:17:51is upvote obviously
- 2:17:54is
- 2:17:55upfold equals one
- 2:17:58and and the main thing is that we need
- 2:18:02to get this for the currently authorized
- 2:18:03user so and
- 2:18:06upvote downloads
- 2:18:09user ID
- 2:18:12equals to something
- 2:18:14so again let's have a look let's get
- 2:18:18this
- 2:18:19um
- 2:18:20get the full idea of this select so
- 2:18:23we're not query from our full downloads
- 2:18:25We are the current user has upvoted this
- 2:18:29where Clause means that
- 2:18:31and finally it's very simple and finally
- 2:18:33we're going to get the category ID and
- 2:18:35post ID
- 2:18:36okay
- 2:18:39so let's wrap this in parenthesis
- 2:18:43and let's give it a like an alias as T
- 2:18:46because we're going to write a join here
- 2:18:48on that and I'm going to give him give
- 2:18:51it an alias like a t
- 2:18:53so now we are left joining on the
- 2:18:55following query
- 2:18:56I'm going to specify here
- 2:18:59this join
- 2:19:01then
- 2:19:02on join
- 2:19:04I'm going to call
- 2:19:05T category ID
- 2:19:10equals to
- 2:19:12CP category ID so I am selecting posts
- 2:19:17which are in this same category
- 2:19:20the user upvote the current user app
- 2:19:23voted posts
- 2:19:25okay and I'm going to specify also we
- 2:19:29don't want to grab the exact same post
- 2:19:32user upvoted in the recommendations
- 2:19:36so that's why we're going to exclude
- 2:19:40t
- 2:19:41which basically at the moment is the
- 2:19:43upvoted pulse ID
- 2:19:45T pulse ID
- 2:19:48does not equal
- 2:19:51to CP post ID
- 2:19:55okay did you get the idea
- 2:19:58okay if not feel free to pause and uh
- 2:20:02listen to the section again so now we're
- 2:20:04gonna grab
- 2:20:06all the posts
- 2:20:08from here now let's put semicolon here
- 2:20:11and we select the post and now we need
- 2:20:14to set bindings so here we use question
- 2:20:17mark and we need to fill that question
- 2:20:19mark by the currently authorized user ID
- 2:20:23and finally let's call get on this and
- 2:20:26have a look if I didn't mean miss
- 2:20:28anything we should see some output of
- 2:20:32recommended posts on the home page
- 2:20:34so here we have that let's output
- 2:20:37recommended
- 2:20:40posts
- 2:20:42save this and have a look
- 2:20:44alt user with his auth manager user
- 2:20:47undefined property okay this is this is
- 2:20:51not a property it is a method
- 2:20:55reload the page okay we have some syntax
- 2:20:58error
- 2:21:00okay we do have that
- 2:21:03near post ID
- 2:21:05from Apple downloads
- 2:21:07okay let's double check everything
- 2:21:11select from upload downloads join
- 2:21:14category post on Apple downloads post ID
- 2:21:18equals category post post ID
- 2:21:20we are upvote downwards is up fault
- 2:21:24equals one and apple downloads user ID
- 2:21:26equals this one
- 2:21:28okay this looks correct so this is a
- 2:21:30left join section then front posts we
- 2:21:33left you into category post as CP on
- 2:21:36post ID equals to cppost ID
- 2:21:40and then here we'll let join on this it
- 2:21:44has nulliest TT
- 2:21:45inside join we add the category ID needs
- 2:21:49to be the same as the category post ID
- 2:21:53and
- 2:21:55the T post ID doesn't equal to category
- 2:21:59posts
- 2:22:00post ID
- 2:22:02and then we select posts here
- 2:22:06wasted bindings
- 2:22:08then we return
- 2:22:10okay where is an actual mistake
- 2:22:14I didn't get it
- 2:22:22okay we need to grab this
- 2:22:25and execute this in the database client
- 2:22:29to check if there is some mistake if
- 2:22:33there's a mistake we are gonna know
- 2:22:35about that
- 2:22:39I know it's no mistake here instead of
- 2:22:41left join yeah definitely we need to
- 2:22:44specify DB row
- 2:22:47so yeah of course
- 2:22:50like in this case as you notice the
- 2:22:53whole select is inside backtics it
- 2:22:56assumed that there was a like database
- 2:22:59expression column name or whatever but
- 2:23:02we need this in to be a row row SQL so I
- 2:23:06save this reload the page
- 2:23:09and now we still have something not
- 2:23:13correct
- 2:23:16so let's check now
- 2:23:18I'm going to grab this again
- 2:23:23and execute here
- 2:23:26and check what mistakes I have
- 2:23:29okay here's something
- 2:23:34here's something now where's the
- 2:23:37database
- 2:23:40here is the database
- 2:23:49here is the problem
- 2:23:52equals is missing isn't it
- 2:23:55yes
- 2:23:57join on category post on this where this
- 2:24:00equals to this
- 2:24:01so I save that reload the page and we
- 2:24:05don't see her anymore which is awesome
- 2:24:06and we see some recommended posts which
- 2:24:09is even more awesome
- 2:24:12okay
- 2:24:13we get how many records we get here we
- 2:24:17don't do obviously all records so let's
- 2:24:20limit this into five
- 2:24:24reload the page okay we see five records
- 2:24:28here
- 2:24:29we need to test if the actual result
- 2:24:32outcome of your query is accurate but we
- 2:24:36anyway need to render them and display
- 2:24:38them so let me actually first do this
- 2:24:44I'm going to use
- 2:24:47a grid layout again for this let's give
- 2:24:50it
- 2:24:51read and grid columns
- 2:24:54columns 1 and above medium screen let's
- 2:24:57give it Creed
- 2:24:59columns 3.
- 2:25:02then we use for each recommended
- 2:25:09posts as hosts and I'm going to use the
- 2:25:13same component X post item in this case
- 2:25:18let's specify
- 2:25:20host here
- 2:25:23actually let's select only three
- 2:25:28here and here as well
- 2:25:31so I save reload and just like this we
- 2:25:36see latest three posts
- 2:25:39well let's give it
- 2:25:42gap of three maybe
- 2:25:45just are broken which should not be but
- 2:25:48that's not a big deal
- 2:25:54okay
- 2:25:59I don't think the design really fits to
- 2:26:03anything else but
- 2:26:06I guess we can leave this now I we just
- 2:26:09can remove these parts it's not
- 2:26:10necessary so let me actually show how to
- 2:26:12remove this part so that we don't break
- 2:26:14other components where this part is
- 2:26:18actually necessary so I'm going to open
- 2:26:20post item
- 2:26:23component and inside the Constructor
- 2:26:26let's accept wine property
- 2:26:29public
- 2:26:31let's make it Boolean
- 2:26:33Boolean
- 2:26:35let's call this
- 2:26:39show
- 2:26:42author
- 2:26:44by default this is set to True show
- 2:26:46author
- 2:26:48public Boolean
- 2:26:51it should be blue right show author
- 2:26:55we we are using the following components
- 2:26:58so in the post item we always show this
- 2:27:01author we can write if statement if show
- 2:27:06author
- 2:27:07then we show it
- 2:27:12and by default it is true so we
- 2:27:15shouldn't see any difference
- 2:27:18somewhere we have a semicolon which is
- 2:27:20not necessary
- 2:27:23okay by default it's it works in the
- 2:27:25same way however in my home page when I
- 2:27:28use that I can specify show author to be
- 2:27:33false
- 2:27:35and let's see what will happen
- 2:27:38I don't see this author information here
- 2:27:40okay however I see this above
- 2:27:44again a great usage of component how you
- 2:27:47can use it so that you don't break how
- 2:27:50you can modify so that you don't break
- 2:27:52anything else
- 2:27:55okay now the question is why I see those
- 2:27:57components why I see this in recommended
- 2:28:01posts
- 2:28:04well the idea was my query uh the idea
- 2:28:07of my query was that two
- 2:28:10to show only those posts which I have
- 2:28:14upvoted and the other posts which are in
- 2:28:17the same category I have reported so I
- 2:28:19think I have upvoted this particular
- 2:28:22post so I shouldn't actually be seeing
- 2:28:24these posts so this we are close is
- 2:28:28inside left join
- 2:28:29and I guess this is not 100 accurate so
- 2:28:34we should add right here additional wear
- 2:28:38we are T post ID
- 2:28:42does not equal to CP post ID
- 2:28:47here we can use cppost ID or posts ID
- 2:28:51it's going to be the same
- 2:28:53so I save that reload the page
- 2:28:56and we have something broken
- 2:29:01let's see column T post ID
- 2:29:08invalid parameter number
- 2:29:14okay I think what we need to do instead
- 2:29:16of this T post ID needs to be wrapped in
- 2:29:20a DB row maybe because we have this t
- 2:29:25inside DB row
- 2:29:29like here this T Alias inside this DB
- 2:29:33row so if I specify it like this
- 2:29:36and we can let's change this into posts
- 2:29:39ID
- 2:29:41reload the page
- 2:29:44invalid parameter number
- 2:29:49is this actually a problem
- 2:29:53like if I comment this out
- 2:29:55yeah it works
- 2:29:57if I uncomment this
- 2:30:00it does not seem to be working
- 2:30:12okay let's check what is the actual
- 2:30:14select
- 2:30:19this is Select
- 2:30:21let's open and paste when to slow down
- 2:30:25and understand what's going on
- 2:30:27we are T post ID doesn't equal to
- 2:30:30question mark why it is a question mark
- 2:30:38well it should not be question right
- 2:30:41okay let's do it vice versa
- 2:30:44we are
- 2:30:47that's it
- 2:30:49post ID yeah we need to specify First
- 2:30:52Column name
- 2:30:53and then the column name operator and
- 2:30:57right here we just we need this TV row
- 2:30:59okay it should not be assumed that this
- 2:31:01is a value instead we pass DB roll if I
- 2:31:04save this and reload we see
- 2:31:08yeah this is exactly what I wanted to
- 2:31:10see so I see now two posts in my
- 2:31:13recommended posts and those posts are in
- 2:31:16the same category in the JavaScript
- 2:31:18category I have upvoted one JavaScript
- 2:31:21post and I see other two posts
- 2:31:26recommended for me because I have 40
- 2:31:28JavaScript posts this is awesome isn't
- 2:31:30it so now if I go
- 2:31:33and let's give this one this total
- 2:31:36Managed IT okay whatever click edit
- 2:31:39let's give it JavaScript as well
- 2:31:42JavaScript category and when to make
- 2:31:45this active
- 2:31:46save enroll the page now we see this
- 2:31:50here as well in my recommended posts the
- 2:31:53image is broken not sure why
- 2:31:57[Music]
- 2:31:57um
- 2:31:58here it wasn't actually broke was it
- 2:32:01yeah whenever we update how whenever we
- 2:32:04update it the image gets broken and this
- 2:32:07is something probably we need to take
- 2:32:10care of if I click on this and edit
- 2:32:13I don't even see this image here even
- 2:32:16though the image is presented here
- 2:32:20okay we can take care of this this is a
- 2:32:23slightly different problem not exactly
- 2:32:25what we are trying to do at the moment
- 2:32:27we're trying to make the home page uh
- 2:32:30really active and working and now let's
- 2:32:33focus on recent categories okay before
- 2:32:36we move on the recent categories let me
- 2:32:37move this comment up maybe
- 2:32:41here for the else statement like this
- 2:32:46and now let's do this so in this case I
- 2:32:49want to select categories
- 2:32:52category
- 2:32:54query
- 2:32:56where
- 2:32:59um
- 2:33:00hold on so I want to select category
- 2:33:04with posts so I'm going to use weed
- 2:33:08I want them with a post let's specify
- 2:33:11any array here
- 2:33:12with posts
- 2:33:16I'm going to use function here we have
- 2:33:19query
- 2:33:20and then on the query I'm going to
- 2:33:23Execute order by descending I want to
- 2:33:27sort them by descending published it
- 2:33:32okay perfect
- 2:33:35we need to query basically only
- 2:33:37categories like select categories
- 2:33:42everything I want to also select
- 2:33:47select select row I'll select role
- 2:33:52um
- 2:33:52like the maximum date so what's the idea
- 2:33:56of the categories I should have probably
- 2:33:57started from there so what categories I
- 2:34:00want to show there I want to show the
- 2:34:03categories
- 2:34:05which contains the recently published
- 2:34:09article so basically it turns out to be
- 2:34:12a recent category because something
- 2:34:14happened inside that category a new post
- 2:34:17has been published like if there is a
- 2:34:19PHP
- 2:34:21category which has the latest post and
- 2:34:24recently I published a new Post in the
- 2:34:27JavaScript category the JavaScript
- 2:34:29category will need to like need to be at
- 2:34:32the top of these category lists
- 2:34:36okay so in the select row I want to
- 2:34:39select the maximum date of
- 2:34:42uh we need join obviously so let's try
- 2:34:46to join first
- 2:34:47left and join
- 2:34:50on category
- 2:34:52category post
- 2:34:54we are categories
- 2:34:57ID
- 2:34:59equals to
- 2:35:01category post
- 2:35:05um
- 2:35:06category ID
- 2:35:09okay
- 2:35:10we need to also join
- 2:35:14on posts
- 2:35:18where
- 2:35:19posts
- 2:35:22ID
- 2:35:23equals
- 2:35:26to category
- 2:35:28post
- 2:35:30ID
- 2:35:33and now we have from categories we
- 2:35:37joined to category post and join to
- 2:35:39posts and now I want to query what is
- 2:35:42the maximum published it date
- 2:35:48um let's give it an alias Max state
- 2:35:50which is the maximum publish date for
- 2:35:53that specific category okay and then I
- 2:35:56want to order by descending by this Max
- 2:36:00state so I order categories based on the
- 2:36:04maximum date of its published posts
- 2:36:09I hope this makes sense I can't explain
- 2:36:12this any better
- 2:36:13so Group by categories ID
- 2:36:18and then we're going to limit this to
- 2:36:20get the five categories and it should be
- 2:36:23integer by the way I don't know why I
- 2:36:24typo string
- 2:36:26and
- 2:36:28finally we call get
- 2:36:30now I should have
- 2:36:32top five categories
- 2:36:35with
- 2:36:36are sorted by the maximum published date
- 2:36:39descending of those posts inside those
- 2:36:43categories okay so I'm going to pass now
- 2:36:47these categories to
- 2:36:49to view let's do this
- 2:36:52on its own line like this and now if we
- 2:36:57go in the home blade this is the last
- 2:37:00section what we are gonna implement
- 2:37:04so we're going to iterate over
- 2:37:06categories
- 2:37:10is category
- 2:37:13let's create div
- 2:37:16we're gonna create H3 and let's output a
- 2:37:21category
- 2:37:25category title
- 2:37:32and then we're going to iterate posts
- 2:37:36and output those posts
- 2:37:40so for this
- 2:37:43um let's use Forge again
- 2:37:45category
- 2:37:47posts is post
- 2:37:51let's create
- 2:37:53I'm going to create one div again with
- 2:37:56class read and grid calls uh calls one
- 2:38:01and above medium let's give it grid
- 2:38:05calls three
- 2:38:06let's give it cap three as well
- 2:38:09so this combines all the nested holes
- 2:38:14and yeah for each post also we need only
- 2:38:19for each category we also need like
- 2:38:21three posts so
- 2:38:23here probably order by descending we can
- 2:38:26specify limit three as well
- 2:38:30now we have three posts for each
- 2:38:32category
- 2:38:34and and I can use the exact same
- 2:38:39component X post item passing post here
- 2:38:46and we can also pass
- 2:38:49um show author to be false we don't want
- 2:38:52the author to be displayed
- 2:38:55okay let's remove this extra div
- 2:38:58and see what's going to be the output
- 2:39:01below the page
- 2:39:02okay we see laravel we see PHP those are
- 2:39:06two categories
- 2:39:07but we actually don't see items
- 2:39:11here so if I print category posts let's
- 2:39:15see what it is
- 2:39:16yeah they are empty empty arrays
- 2:39:21laravel and PHP why I don't see
- 2:39:26why I don't see JavaScript
- 2:39:29inside categories
- 2:39:33okay strange so let's let's have a look
- 2:39:36so from category let's if I remove this
- 2:39:39with completely
- 2:39:41okay so I select categories
- 2:39:44I have this date left join everything
- 2:39:48okay this looks good
- 2:39:51reload the page I see no JavaScript here
- 2:39:58okay I see something promising so let's
- 2:40:02remove this and have a look so we see
- 2:40:10hold on
- 2:40:11recent categories here we here we go so
- 2:40:13this is Javascript and all the
- 2:40:15categories inside JavaScript
- 2:40:18okay
- 2:40:19then we have laravel and all the uh all
- 2:40:22the posts excuse me from the laravel and
- 2:40:25then we have PHP and all the posts from
- 2:40:27PHP
- 2:40:29okay
- 2:40:31if I specify I want categories with
- 2:40:35posts
- 2:40:38if I just remove this weird
- 2:40:43okay I still get that perfect
- 2:40:47now if I Execute order by
- 2:40:50um published it
- 2:40:52in the limit three that completely
- 2:40:54changes the picture so for JavaScript we
- 2:40:57see that
- 2:40:59but I think this limit three
- 2:41:03is added
- 2:41:06here
- 2:41:07so it actually if I specify limit to one
- 2:41:13now it works perfectly actually on
- 2:41:17on JavaScript
- 2:41:25well actually let's try to remove this
- 2:41:28wave and in this case we should see
- 2:41:32everything what we expect and in the
- 2:41:35home blade
- 2:41:37maybe I can execute get posts and
- 2:41:40provide the limit here and get
- 2:41:44the limits like a three
- 2:41:47let's specify only with three here
- 2:41:50okay if I reload
- 2:41:54category
- 2:41:56um that should be posts simply posts
- 2:41:59okay now let's check this
- 2:42:02uh recent categories we have JavaScript
- 2:42:04three items for lateral one and for p if
- 2:42:07you want so that actually works
- 2:42:10keep in mind that right now we are
- 2:42:13executing this query for each category
- 2:42:16well at the moment we have only five
- 2:42:18categories which is fine but if you have
- 2:42:22X amount of categories in categories and
- 2:42:27then you're going to execute
- 2:42:29query for each category
- 2:42:31uh you're gonna basically have a kind of
- 2:42:35database issues not maybe issues but
- 2:42:37you're gonna put extra load to the
- 2:42:40database
- 2:42:41so it's going to be good and I'm going
- 2:42:42to do this to debug why these parts this
- 2:42:47code doesn't work as expected I expected
- 2:42:50it to limit posts
- 2:42:54make a query for posts once and limit
- 2:43:00uh limit for each category but yeah I
- 2:43:02think we need to do it slightly
- 2:43:04differently so that's why I'm going to
- 2:43:05comment this out and again because this
- 2:43:08is a home page and we have a limited
- 2:43:09number of categories that's fine in my
- 2:43:12opinion in this case
- 2:43:13okay what we need to do
- 2:43:18is
- 2:43:19um either some formatting to
- 2:43:23this
- 2:43:26so this is like a text
- 2:43:30text large
- 2:43:32let's give it
- 2:43:33text maybe Center
- 2:43:40let's give this one also
- 2:43:43margin button like all of them
- 2:43:47plus margin button or
- 2:43:51maybe here as well
- 2:43:54margin button four
- 2:43:59I think it should be
- 2:44:01eight
- 2:44:06uh okay and we have this
- 2:44:09JavaScript here let's give it also font
- 2:44:13bold
- 2:44:14maybe even text the Excel
- 2:44:22okay not too bad
- 2:44:26give it margin bottom six
- 2:44:34okay that's perfect like we have recent
- 2:44:37categories
- 2:44:40and yeah of course
- 2:44:43that should work why it doesn't work
- 2:44:46okay probably because this article is
- 2:44:49not published
- 2:44:50and we cut something
- 2:44:53we don't specify here
- 2:44:57in the home blade we don't specify
- 2:45:02uh
- 2:45:04that we need published posts
- 2:45:08so if I open now post
- 2:45:12and we have this
- 2:45:16um
- 2:45:17from category basically we have these
- 2:45:19posts
- 2:45:20I can Define one more that's going to be
- 2:45:23published
- 2:45:25posts
- 2:45:27and we can run extra wear closes here
- 2:45:31and I'm going to copy this again from
- 2:45:34from here we are active in published
- 2:45:37status in the past
- 2:45:39like this
- 2:45:41click ok
- 2:45:44let's move this down
- 2:45:46and in the home blade I'm going to use
- 2:45:49published posts so if I say this now and
- 2:45:53reload the page I don't see anything in
- 2:45:56the lateral I see one PHP click on this
- 2:45:59that works however we don't have laravel
- 2:46:03category posts
- 2:46:04published
- 2:46:06and
- 2:46:07if we go in the post controller
- 2:46:11in the categories
- 2:46:14it's good to add one extra as filter his
- 2:46:19posts so basically if the category
- 2:46:21doesn't have posts it doesn't make sense
- 2:46:23to display it right here so if I just
- 2:46:25refresh the page I should not see
- 2:46:27lateral here but I see because it
- 2:46:31actually has
- 2:46:32one post and this has does not check
- 2:46:38uh whether the post is published or not
- 2:46:40so I think we can
- 2:46:43and add an extra Wear close here
- 2:46:48uh let's grab query
- 2:47:00okay I don't know if we can this has if
- 2:47:06that supports the filter okay laravel
- 2:47:10uh we're
- 2:47:14has something like this
- 2:47:17I think there's I remember now so there
- 2:47:20is something like where
- 2:47:22has exactly like this we specify posts
- 2:47:27and we specify function
- 2:47:29like this
- 2:47:31we get query here and then on that query
- 2:47:35we run where category active and this
- 2:47:41part and the publish that is in the past
- 2:47:46okay now let's check this
- 2:47:50refresh the page okay live will
- 2:47:52disappeared exactly as we expected there
- 2:47:54are no active posts in the laravel
- 2:47:58category that's why it should not be
- 2:47:59rendered if I open the page and search
- 2:48:03for I don't know which one is
- 2:48:06from laravel this one which is not
- 2:48:09active
- 2:48:10I activate this let's click edit
- 2:48:14then active save changes go on the home
- 2:48:17page refresh now we see laravel right
- 2:48:20here
- 2:48:22okay so this is our new home page we
- 2:48:25have
- 2:48:26latest post we have popular posts
- 2:48:30we have recommended posts
- 2:48:32for me and we have recent articles
- 2:48:36JavaScript laravel PHP any file logout
- 2:48:40recommended section should be different
- 2:48:43now I see different output right here
- 2:48:47okay I think this is this is really good
- 2:48:52all right I'm gonna make small design
- 2:48:55adjustments on the on the home page I'm
- 2:48:58going to remove these recent categories
- 2:49:00and instead put Javascript right here
- 2:49:02and I'm going to also link it to the
- 2:49:05actual categories page where you can
- 2:49:07find all the JavaScript posts
- 2:49:10and I'm going to also adjust the height
- 2:49:13of the image because right here we see
- 2:49:16that this one has smaller height this
- 2:49:17one has large so let's make it fix give
- 2:49:20it another like aspect ratio of like a
- 2:49:23three by four or something like this and
- 2:49:26then we we will be sure that we will
- 2:49:28have the same hate for article and then
- 2:49:31we will have title as well as the body
- 2:49:35like I'm I have zoomed in very very
- 2:49:37zoomed in
- 2:49:38version in my browser that's why I have
- 2:49:42a huge huge letters here and when you
- 2:49:45zoom out actually it's going to be
- 2:49:47tested in a hundred percent there there
- 2:49:49might be necessary to adjust the font
- 2:49:52size it says right Etc okay let's start
- 2:49:54with small things and then then we're
- 2:49:56gonna move on much much bigger thing
- 2:49:58which gonna be implementing comments
- 2:50:01comments section all right so let's open
- 2:50:05um this blog and I'm gonna go in the
- 2:50:09post item section
- 2:50:14here
- 2:50:17and yeah the post item component
- 2:50:19basically is used on multiple places
- 2:50:21right here and it is used right here and
- 2:50:25we also have it used on the home page
- 2:50:30um no on the inner page no this is
- 2:50:33something else okay anyway so we have
- 2:50:35this in two places right here and right
- 2:50:37here so we need to give it a proper
- 2:50:40aspect ratio to put the image properly
- 2:50:44so let's give this one
- 2:50:46um also out
- 2:50:48there's going to be
- 2:50:50post
- 2:50:52title but speaking about the aspect
- 2:50:55ratio let's search for
- 2:50:57aspect ratio
- 2:51:00Tailwind CSS there is one plugin
- 2:51:04necessary to be installed I'm not sure
- 2:51:06if this comes with the basic
- 2:51:09installation
- 2:51:12it might it might be coming
- 2:51:16okay let's check
- 2:51:19um we don't own Square
- 2:51:23here we have that aspect Square we can
- 2:51:27customize that and provide
- 2:51:30three by four or four by three as we
- 2:51:34want
- 2:51:35or provide it like this like arbitrary
- 2:51:38value this is what I want in classes for
- 2:51:42the Post item
- 2:51:44so let's give it aspect
- 2:51:48three
- 2:51:49by four no four by three we want it to
- 2:51:52be in the landscape mode well that's why
- 2:51:55let's specify 4x3 if we reload page we
- 2:51:58see huge image okay the good thing is
- 2:52:02that the hate now is always the same and
- 2:52:05I think that's much better
- 2:52:08but the images images very stretched
- 2:52:12which we want to fix so if we specify
- 2:52:15objects
- 2:52:17cover
- 2:52:19let's have a look
- 2:52:21okay
- 2:52:22now we don't see the whole image let's
- 2:52:24specify object contain
- 2:52:28okay I think this is what we want
- 2:52:32so we have image always visible we have
- 2:52:35three four by three which
- 2:52:38which is kind of okay
- 2:52:42however we can even customize this post
- 2:52:45item component just like we customized
- 2:52:49let me show you
- 2:52:50so right here we have this show author
- 2:52:52and in the same way we can add one extra
- 2:52:54parameter which will Define the image
- 2:52:57properties image aspect ratio whatever
- 2:53:00we want and then we can use these for
- 2:53:03um for like big size we can do
- 2:53:07differently for uh for below we can do
- 2:53:09it different like this is fine for me
- 2:53:11but this is a little bit too large isn't
- 2:53:15it
- 2:53:20okay we can leave this at the moment I'm
- 2:53:23going to leave it
- 2:53:24one additional thing the images are
- 2:53:27broken and that basically happens
- 2:53:29because
- 2:53:30we are using
- 2:53:32seed data and we don't have actually
- 2:53:35uploaded images
- 2:53:37if I just click on this
- 2:53:39and if I make some changes right here
- 2:53:42then these images
- 2:53:44is not going to be lost like
- 2:53:46specified 2 here save that below the
- 2:53:50page we see two right here but the image
- 2:53:52is not lost images are only lost
- 2:53:54whenever we update that specific article
- 2:53:57which has that seed dummy URL right
- 2:54:02there save changes go back and then this
- 2:54:06is actually lost but that's fine because
- 2:54:09we are not gonna spend time on to fix
- 2:54:11some C data which is only created for
- 2:54:14like demonstration purposes okay I think
- 2:54:19we can move on the comment section uh
- 2:54:22before that actually
- 2:54:23um as I said I want to change these
- 2:54:26recent categories how that is rendered
- 2:54:28so I'm going to look for resend
- 2:54:31categories here I have this on home page
- 2:54:34and I'm going to move this for each
- 2:54:38right right here
- 2:54:42okay then this end for each goes out
- 2:54:46right here so now I iterate over
- 2:54:48categories instead of recent categories
- 2:54:50I'm going to type the category title
- 2:54:53right here
- 2:54:55that's perfect and we also have these
- 2:54:59uh continue reading icon Arrow icon I'm
- 2:55:03going to copy this icon and put this
- 2:55:05next to the category title
- 2:55:10so if I say this now I see JavaScript
- 2:55:12with the arrow and I'm going to make
- 2:55:15this Arrow
- 2:55:16to link on an actual category page
- 2:55:20if we open web.php we see we have this
- 2:55:24the following URL by category we need to
- 2:55:26provide the category slug so let's use
- 2:55:30root
- 2:55:32by category and actual category
- 2:55:36so I save this reload the page and if I
- 2:55:38click this right now it opens the
- 2:55:41category laravel and shows me all the
- 2:55:43posts I have on laravel category which
- 2:55:47is exactly what I wanted
- 2:55:49okay I think this is awesome so we have
- 2:55:53recommended posts and then JavaScript
- 2:55:55okay I'm gonna add additional text right
- 2:55:58here hosts for category
- 2:56:03JavaScript
- 2:56:05like this
- 2:56:07here we go
- 2:56:12pose for category JavaScript post for
- 2:56:15category laravel and so on I think
- 2:56:19category reliable this will be also good
- 2:56:21enough
- 2:56:22all right that's it for this video and I
- 2:56:25hope you like it if so maybe you want to
- 2:56:27hit the like button and maybe you want
- 2:56:29to check my another project where I
- 2:56:31created portfolio the codetholic.com in
- 2:56:33laravel 9. you can find this video right
- 2:56:36here thanks for watching and I will see
- 2:56:38you in the next time
About this transcript
This page contains the full transcript of Laravel Blog: Roles & Permissions, Likes & Dislikes, View Count | Part 2 by The Codeholic, generated from the public captions YouTube serves with the video. The transcript has 22,649 words across 3,650 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.