YouTube2Text

Laravel Blog: Roles & Permissions, Likes & Dislikes, View Count | Part 2 — Transcript

by The Codeholic · 22,649 words · 3,650 segments · language en · Watch on YouTube

Full transcript

  1. 0:00I'm building blog websites with admin
  2. 0:02panel in lateral 10. if you haven't
  3. 0:04watched the first part click right here
  4. 0:06in this video we are going to add user
  5. 0:08registration login email verification
  6. 0:09password reset with alarable Breeze we
  7. 0:12will install spotty permissions package
  8. 0:14and create user and admin roles and
  9. 0:16restrict access to admin panel we will
  10. 0:18Implement post likes and dislikes using
  11. 0:21laravel Livewire we will count number of
  12. 0:24views on post and then in admin panel we
  13. 0:26will output analytics such as number of
  14. 0:28views number of likes or dislikes for
  15. 0:30each post we will Implement brand new
  16. 0:32homepage with four main sections latest
  17. 0:35article the most popular three articles
  18. 0:38based on likes recommended articles
  19. 0:41based on user likes history if the user
  20. 0:43is authorized if the user is guessed
  21. 0:45then we're going to show recommended
  22. 0:47articles based on number of views we're
  23. 0:49going to show top categories by their
  24. 0:51latest posts we will add search field
  25. 0:54for posts and categories in admin panel
  26. 0:56we're going to fix and improve multiple
  27. 0:58minor things
  28. 1:04comments on the post s Implement Global
  29. 1:07search on the website and maybe deploy a
  30. 1:11project on production environment with
  31. 1:13custom domain
  32. 1:16don't tell anyone and maybe you don't
  33. 1:19want to subscribe because you're
  34. 1:21constantly checking my YouTube channel
  35. 1:23if I uploaded any new video alright no
  36. 1:26further Ado let's jump into the video
  37. 1:28now let's start working on user
  38. 1:30registration and logging and for this
  39. 1:33we're going to use laravel Breeze uh you
  40. 1:36can have a look at the lateral Breeze
  41. 1:37documentation is pretty straightforward
  42. 1:39to install that
  43. 1:40I'm going to have the documentation
  44. 1:42always opened and even though I know
  45. 1:45what comments I should type it's always
  46. 1:47you're going to always make much less
  47. 1:50mistakes when you actually copy these
  48. 1:51and like don't have a typo when you're
  49. 1:55typing okay so I'm gonna
  50. 1:57um actually first we're gonna start the
  51. 2:00server vendor being sale up then we're
  52. 2:06gonna go inside the container
  53. 2:08Bender actually
  54. 2:11I'm going to exit this stop that and I'm
  55. 2:15going to start my application in a
  56. 2:17detached mode
  57. 2:19so vendor Bean sale app testing
  58. 2:23okay containers have been started now
  59. 2:26let's access the container when you're
  60. 2:27being
  61. 2:28sale Bash
  62. 2:31and now from inside that container we're
  63. 2:34going to execute composer require
  64. 2:35lateral Breeze Dev
  65. 2:37okay that was installed then we're gonna
  66. 2:39execute
  67. 2:41uh PHP
  68. 2:44artisan
  69. 2:46Breeze column install
  70. 2:49that will ask whether which stack we
  71. 2:51want to install so we are not using view
  72. 2:55or reactor API in this case so I'm going
  73. 2:57to provide the zero right here whether
  74. 2:59we want to install Dark mode support I'm
  75. 3:02going to provide no right here if we
  76. 3:05want tests no right here as well and we
  77. 3:08have an error and that error was
  78. 3:10expected because lateral Breeze is
  79. 3:13intended to be installed as a very first
  80. 3:15thing after you create your level
  81. 3:17application so it expects welcome blade
  82. 3:21PHP to exist on the reviews folder which
  83. 3:24doesn't exist so that's why we have this
  84. 3:26problem now I'm going to open
  85. 3:29resources views and simply I'm going to
  86. 3:33copy and paste homeblade and call this
  87. 3:35welcome blade PHP so I'm not going to
  88. 3:39use this welcome blade but I am simply
  89. 3:42creating this because lateral Breeze
  90. 3:43needs that and then later when lateral
  91. 3:46Breeze installs I'm going to adjust the
  92. 3:48content and create and maybe modify a
  93. 3:51few views and so on okay before we
  94. 3:54execute lateral Breeze one like a
  95. 3:57disclaimer lateral Breeze will modify
  96. 3:59your views and layouts and few other
  97. 4:01things so make sure you have everything
  98. 4:04picked up like for example and my
  99. 4:07recommended way to backup everything is
  100. 4:09using git so use version control system
  101. 4:12and comment everything before you run
  102. 4:15lateral Breeze in this case because as I
  103. 4:17mentioned It's Gonna Change many things
  104. 4:19in your project okay I have everything
  105. 4:21commented I'm Not Afraid about losing
  106. 4:23anything so I'm going to execute please
  107. 4:26insta zero no and no
  108. 4:30now let's wait few seconds Breeze was
  109. 4:33installed then it run npm install and
  110. 4:35npm run the npm Run build we're going to
  111. 4:38execute npm run Dev
  112. 4:40by ourselves and now let's have a look
  113. 4:44so here's our application and let's
  114. 4:47access to the main page and we have
  115. 4:50undefined variable posts and that comes
  116. 4:53from welcome blade okay welcome blade
  117. 4:55was used by laravel Breeze automatically
  118. 4:57now let's open web.php which is our main
  119. 5:01roads file
  120. 5:03and right here everything was modified
  121. 5:05by lateral priests so this like a CN
  122. 5:09color line indicates that I have changes
  123. 5:12that uh changes come from version
  124. 5:14control system so basically if I click
  125. 5:17this I see what was my previous version
  126. 5:19so I'm going to copy this part and at
  127. 5:22the very very bottom I'm going to put
  128. 5:25that so my roads and also at the top
  129. 5:28these Imports have been changed I'm
  130. 5:30going to copy this and I need profile
  131. 5:33controller but I need my post controller
  132. 5:36inside controller as well so now in my
  133. 5:39web HP I have uh like modifications
  134. 5:42bilateral Breeze as well as my previous
  135. 5:44rows what I had before so small hint
  136. 5:49right here don't put these above because
  137. 5:53this is a very very generic route so it
  138. 5:57is matching all the everything
  139. 6:00if the previous rows didn't match so
  140. 6:03whenever you try to access a dashboard
  141. 6:05or profile or any other robe declared
  142. 6:07before this will match and it will it
  143. 6:11will use that
  144. 6:13so this needs to be at the very bottom
  145. 6:15if you don't believe me you can put this
  146. 6:17at the very top and you can just try to
  147. 6:19access like other pages and you will see
  148. 6:21an error okay I'm going to save these
  149. 6:24and let's modify a few things I don't
  150. 6:26need this uh welcome because I am using
  151. 6:30the post controller index and let's save
  152. 6:33this and have a look so we have this
  153. 6:35error that comes from navigation blade
  154. 6:38navigation blade is something also
  155. 6:41introduced by Laurel Breeze and let's go
  156. 6:44in The Roots resources Fields views
  157. 6:49layouts and right here we have this up
  158. 6:51plate and right here like almost every
  159. 6:54line was changed by lateral Breeze
  160. 6:56I want to recover my previous layout but
  161. 6:59I need few things from here like for
  162. 7:02example
  163. 7:03white scripts CSS and javascripts which
  164. 7:07I want to put in my layout and maybe
  165. 7:11also later we can move our header into
  166. 7:14layouts navigation and so on so I'm
  167. 7:17going to copy everything and create new
  168. 7:20temporary file like scratch file and I'm
  169. 7:22going to paste everything right here and
  170. 7:25I'm going to revert everything using
  171. 7:27version control system if you had up
  172. 7:29late PHP picked up then you can easily
  173. 7:32revert that so I'm gonna select
  174. 7:34everything and type a control alt and Z
  175. 7:37on my keyboard and it's gonna
  176. 7:40that's going to revert everything inside
  177. 7:42this file I save this rule of the page
  178. 7:45and we have another problem and that
  179. 7:47comes from the layout again but that
  180. 7:50happens because the component was
  181. 7:53changed the layout component if we go in
  182. 7:55the app view app layout right here a few
  183. 7:59things have been completely removed like
  184. 8:01the Constructor was removed so I'm going
  185. 8:04to revert that so I need this and also
  186. 8:07Imports have been removed I'm going to
  187. 8:09revert this as well so now I save this
  188. 8:12and reload the page Nic application
  189. 8:14working right so I can navigate between
  190. 8:17pages and that was completely fine
  191. 8:20however if I try to access like login
  192. 8:23for example we don't have styles at all
  193. 8:26so how we're going to do that now let's
  194. 8:29open the scritch file and I'm going to
  195. 8:31copy these white tag and let's open up
  196. 8:36blade scroll up and I'm going to put
  197. 8:39this uh before closing headtech
  198. 8:43like this
  199. 8:45this actually these resources app.js if
  200. 8:48we have a look
  201. 8:49uh let's go under resources JS and
  202. 8:53app.js this uses Alpine this Imports
  203. 8:56Alpine so we have already Alpine and we
  204. 8:59can remove this JavaScript from CDN if
  205. 9:02we open these app CSS this uses Talon
  206. 9:05CSS so we can completely remove these
  207. 9:08Talon CSS from CDN which is fine great
  208. 9:12now if we save this and reload we see
  209. 9:16our Styles in JavaScript is completely
  210. 9:18broken
  211. 9:20and that as I figured out is kind of bag
  212. 9:23of laravel sale in white combination of
  213. 9:28together if I try to access any URL
  214. 9:30these styles are not there if I open
  215. 9:32developer tools
  216. 9:33and expand that reload we see that error
  217. 9:38address is invalid now let's go in the
  218. 9:41white config it is in the root of the
  219. 9:46project and right here at the very top
  220. 9:48we're going to add server we're going to
  221. 9:51provide HMR
  222. 9:53and we're going to provide host to be
  223. 9:56localhost
  224. 9:58you should provide right here
  225. 10:00whatever is the domain your local domain
  226. 10:04okay so I'm going to save that
  227. 10:07and now if I reload these it's going to
  228. 10:10take a few seconds but now we see that
  229. 10:13the styles are big
  230. 10:15and we can navigate and we see
  231. 10:18everything is okay and we can also try
  232. 10:21to access login page and styles are
  233. 10:24there
  234. 10:25now this login page doesn't have header
  235. 10:27and footer which is something I want my
  236. 10:29blog to have my the login page of my
  237. 10:33blog to have also
  238. 10:35um the forward password as well as the
  239. 10:38registration all of them needs to have
  240. 10:40this header and footer
  241. 10:42those files are defined by lateral
  242. 10:45Breeze and they are available under
  243. 10:47resources views all folder and if we
  244. 10:51have a look all of those files have the
  245. 10:54layouts the main component they are
  246. 10:56using is the guest layout
  247. 10:59and if we open now guest layout
  248. 11:02there are obviously no header in footer
  249. 11:05and this is the guest layout and this is
  250. 11:07something I want to modify so that
  251. 11:11header and footer to be there so this is
  252. 11:14a layout but I'm going to actually
  253. 11:15change this slightly I'm going to remove
  254. 11:18this body and head completely let's
  255. 11:21remove this HTML as well and this right
  256. 11:26now is a guest layout but I want this to
  257. 11:31extend X up layout
  258. 11:34okay now let's format the code and now
  259. 11:39whenever the login form is rendered
  260. 11:41here's the login form it has
  261. 11:44this HTML included which on its own is
  262. 11:49extending the app layout okay we
  263. 11:52probably we probably don't need
  264. 11:54everything maybe we don't need logo we
  265. 11:56can remove that
  266. 11:57mean h screen maybe this is something we
  267. 12:00can remove as well
  268. 12:03and that's more like it there is
  269. 12:05probably some kind of padding padding
  270. 12:07top and we can remove that PG gray maybe
  271. 12:11we can remove it
  272. 12:13save
  273. 12:15okay that's much better and I want this
  274. 12:18form to be in the center
  275. 12:20so we have this justify Center but we
  276. 12:24have this uh under above small screens
  277. 12:27which we don't need
  278. 12:29we wanted this to be always in the
  279. 12:31center
  280. 12:32and we have with full
  281. 12:37maybe we can remove this with full and
  282. 12:40Max with medium margin top padding
  283. 12:46let's remove all that and have a look
  284. 12:50okay we need paddings
  285. 12:52we need padding
  286. 12:55how to put this in the center let's
  287. 12:58remove this w
  288. 12:59okay now let's inspect this and have a
  289. 13:01look so this is the
  290. 13:04this is the form
  291. 13:07this is the container okay the container
  292. 13:10which
  293. 13:12I see so the container comes from the
  294. 13:14app layout
  295. 13:16and if we open up layout and find where
  296. 13:20the main content is injected right here
  297. 13:23and if we just provide right here
  298. 13:25justify Center Maybe
  299. 13:29justify justify Center then the full
  300. 13:33form will go in the center or maybe we
  301. 13:36can undo these
  302. 13:38and open
  303. 13:41this guest blade
  304. 13:43and give this one w
  305. 13:47ool always
  306. 13:49and then this one already has justify
  307. 13:52Center okay I think that's better like
  308. 13:55making a change in the up blade is kind
  309. 13:57of okay but because the upload is used
  310. 14:00on other Pages as well it's not 100
  311. 14:03correct to make change right here
  312. 14:05instead making changes in the guest
  313. 14:08blade will be much more safe we are sure
  314. 14:11that we aren't going to break home or
  315. 14:14any other pages
  316. 14:15okay that's perfect now every out page
  317. 14:19is in the layout
  318. 14:21I don't actually like the width of the
  319. 14:24forms so maybe we can do something Max
  320. 14:28with
  321. 14:29instead of MD maybe we can provide LG
  322. 14:36we need to wait
  323. 14:41uh okay
  324. 14:44it didn't work for some reason
  325. 14:49that has
  326. 14:51Max with LG
  327. 14:59let's provide Excel
  328. 15:06okay it has Max width but maybe we want
  329. 15:10to Define like a width or Min width as
  330. 15:12well or maybe this is even fine like not
  331. 15:15big deal so we have uh enough width for
  332. 15:19each individual field right
  333. 15:24I cannot I access login
  334. 15:27here I have the login
  335. 15:29okay so now let's try to log in and
  336. 15:32let's take here also putting the login
  337. 15:36and registration buttons in my profile
  338. 15:38buttons in the navigation as well okay
  339. 15:41if I try to log in right now I'm logged
  340. 15:44in this redirects me to the dashboard
  341. 15:47which is uh something we don't we don't
  342. 15:51have at the moment we don't have
  343. 15:52dashboard so probably we don't need that
  344. 15:56at the moment
  345. 15:58so for now I'm gonna simply remove this
  346. 16:02redirect to dashboard and that was
  347. 16:05basically modified in the road service
  348. 16:08provider right here
  349. 16:10that home was changed into dashboard and
  350. 16:13I went actually uh revert this into home
  351. 16:17again
  352. 16:19and now I cannot log I cannot log out
  353. 16:24because I don't have logout link
  354. 16:26okay let's actually take care of the
  355. 16:29putting proper links in the navigation
  356. 16:31right let's open
  357. 16:35navigation blade PHP and let's have a
  358. 16:39look we have couple of links primer
  359. 16:41navigation menu uh we have this
  360. 16:44navigation links which goes to dashboard
  361. 16:48and activates that right here it
  362. 16:51displays the user information who is
  363. 16:54actually authorized at the moment and I
  364. 16:56think that drop down is something we
  365. 16:58might need
  366. 17:01and we also need
  367. 17:06we also need logout
  368. 17:11like we have this here okay if we pay
  369. 17:14attention this is a responsive settings
  370. 17:16option so that is visible for mobile
  371. 17:20that is visible for mobile and the above
  372. 17:23one is visible for
  373. 17:28um for a desktop right but where is the
  374. 17:32actual login
  375. 17:36and sign up
  376. 17:38where's that
  377. 17:40here's the log out let's search for a
  378. 17:43login
  379. 17:45we don't have this here
  380. 17:47we don't have probably this in the guest
  381. 17:49layout probably it was in the
  382. 17:53up blade which
  383. 17:56should be a scratch file now here it is
  384. 18:00so I have the scratch file
  385. 18:02and there was a header
  386. 18:06okay that was coming probably from there
  387. 18:09anyway let's
  388. 18:10go in our up blade
  389. 18:14and we have the following navigation
  390. 18:17links
  391. 18:18and let me actually take one of the
  392. 18:21links
  393. 18:22and put them like this
  394. 18:26okay that should be login
  395. 18:29we're going to adjust CSS
  396. 18:31a little bit later this is register
  397. 18:35let's provide proper tests uh texts
  398. 18:38register
  399. 18:40and this is
  400. 18:43logging so we save and we see login and
  401. 18:46register however they should not be
  402. 18:49visible if the user is already
  403. 18:52authenticated because right now it
  404. 18:54redirects us to home which is also not
  405. 18:56correct and if we open this
  406. 18:58road service provider
  407. 19:02wrote a service provider and if we
  408. 19:05simply change this home into slash that
  409. 19:08will be more accurate clicking redirects
  410. 19:11us to home page we need to hide login
  411. 19:14load login and registration with user is
  412. 19:17already authorized
  413. 19:19so let's use auth
  414. 19:25a directive
  415. 19:29and
  416. 19:30alph
  417. 19:35that should be not Alf to be honest so
  418. 19:40let's do like this if the user is
  419. 19:42authorized we're going to display the my
  420. 19:44profile section then we're going to have
  421. 19:46else
  422. 19:48and we're going to display this so if I
  423. 19:50save now we don't see a login and
  424. 19:52registration which is perfect now if we
  425. 19:56open navigation blade here we have this
  426. 19:59settings drop down which is again for
  427. 20:03desktop the second one is for Mobile in
  428. 20:07this case let's make it simple we
  429. 20:09haven't done any changes regarding
  430. 20:12making our blog responsive so simply I'm
  431. 20:15going to take this part
  432. 20:18and go in the upblade and paste this
  433. 20:21right here I'm doing this only for
  434. 20:23desktop at the moment let's remove this
  435. 20:25hidden
  436. 20:26and let's give it display Flex let's
  437. 20:30save it have a look okay we have this
  438. 20:33drop down uh the profile is available
  439. 20:38and the logout will probably work
  440. 20:40perfect so now we have login and
  441. 20:43register I click on login click on
  442. 20:45register both working let's log in again
  443. 20:48and we have this my profile these styles
  444. 20:50of this my profile of course is not nice
  445. 20:53it should be probably in the styles of
  446. 20:55this so let's give it some small
  447. 21:01let's take the following classes and
  448. 21:03maybe
  449. 21:04modify this part
  450. 21:08yeah there are a lot of classes
  451. 21:10so let's paste this and have a look
  452. 21:15um okay let's give it
  453. 21:18legs
  454. 21:21paint items Center
  455. 21:26okay
  456. 21:28that's good
  457. 21:29let's leave it as it is right now
  458. 21:33or maybe we can put this navigation on
  459. 21:36the left side and these on the right
  460. 21:38side so what I'm going to do
  461. 21:41is we have this widthful and container
  462. 21:45and it has flex and it has Flex column
  463. 21:49as well but those are for mobile okay on
  464. 21:52above small screens we have Flex row
  465. 21:56item Center we don't want justify Center
  466. 21:59let's give it a justify between
  467. 22:04and now let's put those links in a div
  468. 22:11and
  469. 22:12those will be in another div
  470. 22:17like this
  471. 22:19now if I say that
  472. 22:21let's collapse this part if I say that
  473. 22:24this is how it looks like okay so we
  474. 22:27have this main navigation on the left
  475. 22:29side we have this user related
  476. 22:32navigation on the right side if I log
  477. 22:35out I see login and registration right
  478. 22:37here okay that's I think
  479. 22:40that looks much better okay now we have
  480. 22:43the differentiation between the normal
  481. 22:45navigation and the user related
  482. 22:47navigations in ideal case this register
  483. 22:49button even needs to be probably kind of
  484. 22:52Blue by default so why don't we make
  485. 22:55this blue
  486. 22:59and let's give it also text White
  487. 23:02like this so this is already like it's
  488. 23:06try it's takes our attention and we want
  489. 23:09to click that in register uh immediately
  490. 23:12right
  491. 23:14okay so this is what we're we're doing
  492. 23:18right now
  493. 23:20now let's have a look all the files that
  494. 23:22have been modified right now and I'm
  495. 23:24gonna use git for this so road service
  496. 23:27provider was changed into slash that's
  497. 23:29fine up CSS app Javascript was modifying
  498. 23:31that's fine Apple blade was modifying
  499. 23:34modified that's also fine now I don't
  500. 23:37want to these styles to be inside the
  501. 23:40layout so I will open that layout take
  502. 23:44this out from here and open this up CSS
  503. 23:48and paste them here okay so I want them
  504. 23:52to be inside CSS not inside HTML let's
  505. 23:55continue this is the app play that was
  506. 23:57modified we have this welcome blade
  507. 24:00which we don't need at all so that was
  508. 24:03created because of lateral breeze so I
  509. 24:06can delete this welcome blade and
  510. 24:08nothing will be broken
  511. 24:10I hope so if something was broken we're
  512. 24:13gonna of course fix and we we need to
  513. 24:15fix that okay then inside the web uh
  514. 24:19webphp those are the modifications that
  515. 24:21have been made that's fine we have the
  516. 24:24dashboard wrote
  517. 24:27um which
  518. 24:29which we probably need
  519. 24:31maybe we will need this later but at the
  520. 24:35moment
  521. 24:36it is not necessary
  522. 24:40okay let's leave this right now let's
  523. 24:43leave it it doesn't hurt then we have
  524. 24:45this composer Json which is the um which
  525. 24:48will have just lateral Breeze the white
  526. 24:50config and down below all the new files
  527. 24:54that have been generated by lateral
  528. 24:56Breeze like the controllers and we're
  529. 24:59going to have request files and
  530. 25:02components as well as the views
  531. 25:04and we also have some profile partials
  532. 25:07and layouts and test files okay
  533. 25:12so I don't see anything suspicious right
  534. 25:15here so I will be happy to comment those
  535. 25:18changes and make it available just
  536. 25:21um I'm gonna have a look at the final
  537. 25:23check we need to register and we need to
  538. 25:27also verify our email address if that is
  539. 25:31something which comes with a lateral
  540. 25:34Breeze if we open user PHP
  541. 25:38um
  542. 25:38okay
  543. 25:40if you open user PHP we must Implement
  544. 25:43an interface must verify
  545. 25:48Master verify email okay if we don't
  546. 25:51implement this interface whenever user
  547. 25:53registers his email is automatically
  548. 25:55verified and he will be able she will be
  549. 25:59able to access the system without email
  550. 26:01verification this is something uh which
  551. 26:04should be avoided and that's why I'm
  552. 26:08going to implement must verify email and
  553. 26:13now if I try to
  554. 26:15try to register let's use a seven-time
  555. 26:19email mailriate example.com let's
  556. 26:22provide some secure password
  557. 26:26so in it okay let's hit the enter
  558. 26:29okay it looks like we are actually
  559. 26:32authorized and we're in the system
  560. 26:37but
  561. 26:40okay
  562. 26:43this is this is tricky if we try to
  563. 26:46access dashboard right now
  564. 26:49let's have a look
  565. 26:50look at this thanks for signing up
  566. 26:52before getting started could you verify
  567. 26:55your email address by clicking on the
  568. 26:57link we just emailed to you if you
  569. 26:59didn't receive blah blah blah okay so we
  570. 27:02are actually authorized but we are not
  571. 27:04verified that's why
  572. 27:07the I'm going to close every tab
  573. 27:10and now I'm going to open Weber PHP uh
  574. 27:14because we are using verified middleware
  575. 27:16right here uh we aren't able to access
  576. 27:19the dashboard
  577. 27:20but we are able to access profile
  578. 27:24and we are able to update our password
  579. 27:26or delete the account and we are able to
  580. 27:29access the home page we are able to do
  581. 27:31basically everything
  582. 27:33which is
  583. 27:35kind of correct we don't do anything
  584. 27:38suspicious that requires email
  585. 27:41verification at this stage
  586. 27:43but if we are now for example do some
  587. 27:46action such as maybe leaving a comment
  588. 27:49on the article or upvoting an article we
  589. 27:53need to verify we need to be verified to
  590. 27:56do this type of action okay
  591. 27:59that's why maybe we can leave this as
  592. 28:02this right now but we should have
  593. 28:05received email verification which we
  594. 28:07need to verify I'm going to open now
  595. 28:10test email client
  596. 28:13which will be defined as a service in
  597. 28:16the docker composer yml and right here
  598. 28:19we see this mailpeat and which has which
  599. 28:23is exposed on the following Port
  600. 28:268025 so if we open our browser and
  601. 28:30access localhost port 8025
  602. 28:35here we are going to see the client
  603. 28:37which is a local client for every kind
  604. 28:40of email and as we see nine minutes ago
  605. 28:43we received the following email and this
  606. 28:47is the email when we click on these we
  607. 28:49can verify in this is why I love working
  608. 28:52with Docker in general because you can
  609. 28:55set up all your services in a single
  610. 28:57Docker compose yml and test email
  611. 29:00ascending and database and everything in
  612. 29:04a single Docker compost yml and you
  613. 29:06don't need to worry about setting up all
  614. 29:09your clients and environments right
  615. 29:12hey okay if we have a look again the
  616. 29:15problem or the problem but the fact is
  617. 29:18that we our email is not verified now I
  618. 29:21click on this verify email address you
  619. 29:23are logged in I'm on the dashboard now I
  620. 29:25am verified and from now on I'm going to
  621. 29:27use this client whether I want to
  622. 29:29recover password or producer is not the
  623. 29:33user I can use this client and I will
  624. 29:35receive
  625. 29:37every kind of emails right here
  626. 29:41and now if I reload this page even if I
  627. 29:45try to access the page verify email I'm
  628. 29:48redirected on the home page because this
  629. 29:50is the default Road at the moment
  630. 29:52the problem I see here is that Mary can
  631. 29:56actually access to admin panel as well
  632. 29:58which is not correct Mary is a regular
  633. 30:01user what she should be able is to
  634. 30:04probably leave a comment on article
  635. 30:06upvote download but she should not be
  636. 30:09able to access to admin panel unless we
  637. 30:12Define it so but I'm going to Define it
  638. 30:15not like this I want only admin users to
  639. 30:18be able to access and they will be
  640. 30:20managing all kind of content and regular
  641. 30:23users will be able to just comment
  642. 30:25upload download and do things like that
  643. 30:28so we should restrict that and to do so
  644. 30:31I'm going to introduce permissions
  645. 30:34package from Speedy so let's search for
  646. 30:38T permissions and the very first link
  647. 30:41from
  648. 30:44spity.d.be domain will be the
  649. 30:47permissions package let's click on the
  650. 30:50installation that's a very powerful
  651. 30:52package so let's scroll down below and
  652. 30:54find the installation section we're just
  653. 30:56going to run composer require first and
  654. 30:59then this will be automatically done we
  655. 31:01don't need to do this we need to publish
  656. 31:03the config as well as the migration file
  657. 31:05we're going to execute that and we can
  658. 31:08clear the cache and finally we're going
  659. 31:09to execute PHP Artisan migrate okay then
  660. 31:12we're gonna do a few other things like
  661. 31:15uh
  662. 31:16uh entity has roles and probably defined
  663. 31:19roles as well but let's start from the
  664. 31:21very first step what we need to do right
  665. 31:24here like the prerequisites and
  666. 31:26everything is okay we satisfy those and
  667. 31:29now let's open the terminal so in the
  668. 31:32terminal I'm actually writing npm run
  669. 31:34Dev so I'm going to open second terminal
  670. 31:36and I'm going to log in inside the
  671. 31:39container vendor
  672. 31:42Bean sale Bash
  673. 31:47and now I am in the container and I'm
  674. 31:49going to execute composer require let me
  675. 31:52copy the Second Step which will be PHP
  676. 31:54Artisan vendor publish let's copy this
  677. 31:57and their required was installed let's
  678. 32:00now run PHP Artisan vendor publish those
  679. 32:02two files have been published
  680. 32:04permissions PHP inside the config and
  681. 32:07the migration file you can have a look
  682. 32:09at the migrations what is going on if
  683. 32:11you are interested you can find this in
  684. 32:13the database migrations right here and
  685. 32:16you will see that this creates couple of
  686. 32:17tables and this is the basically the
  687. 32:21whole migration which you can explore if
  688. 32:23you're interested okay now let's apply
  689. 32:25PHP
  690. 32:27Artisan
  691. 32:29optimize clear
  692. 32:32and it was cleared then PHP Artisan
  693. 32:35migrate
  694. 32:38all right if we have a look in the
  695. 32:40database schemas you can access to the
  696. 32:42database client uh
  697. 32:45through the um to the MySQL which is
  698. 32:49actually running in the docker and I'm
  699. 32:51going to check right now the database in
  700. 32:53the page performs database client just
  701. 32:55refresh this keymind we see a couple of
  702. 32:57tables like roles model has permissions
  703. 33:00module has roles and so on okay so those
  704. 33:03tables we are created now I'm going to
  705. 33:06open user.php and I'm going to introduce
  706. 33:10a new trade right here has roles it
  707. 33:14comes from Speedy permission trades has
  708. 33:17Rose and now
  709. 33:19I'm going to actually Implement an
  710. 33:22interface so basically regarding
  711. 33:23permissions we did most of the things
  712. 33:25let me try to do one additional thing to
  713. 33:28create the role actual role so the we
  714. 33:32have the database Cedar right here uh
  715. 33:34and actually I'm gonna check what users
  716. 33:37we have we have uh zura and Mary and I'm
  717. 33:41going to create now admin user okay and
  718. 33:43I'm going to Define also admin role as
  719. 33:46well I'm going to comment this post
  720. 33:49Creation in the database theater I don't
  721. 33:51want to create posts that was just for
  722. 33:53testing purposes in the first part and
  723. 33:55by the way if you haven't checked the
  724. 33:57first part first I recommend to check
  725. 33:59check it and then continue watch the
  726. 34:02second part and then now let's create a
  727. 34:05user so let's call this admin user that
  728. 34:09will be user
  729. 34:12Factory
  730. 34:13let's import the user
  731. 34:16app modules user right user Factory
  732. 34:19create let's provide right here email
  733. 34:24will be admin at example.com let's
  734. 34:28provide name it will be admin and let's
  735. 34:33provide password
  736. 34:35that will be back Crypt
  737. 34:38it's provided admin123 okay that's the
  738. 34:41password and now let's create admin role
  739. 34:44as well that will be
  740. 34:47role and that will be spotty permission
  741. 34:51models create and we have to provide a
  742. 34:55name of the role
  743. 34:57that will be admin so the role is
  744. 35:01actually created and then on admin user
  745. 35:04I'm gonna call assign role so this
  746. 35:07assign role method is not seen by Page
  747. 35:11performing it does not autocomplete but
  748. 35:14this assigned role comes from the trade
  749. 35:16we added on the user model so if we just
  750. 35:20Define an annotation right here that the
  751. 35:22admin user variable is actually an
  752. 35:24instance of app models user then when we
  753. 35:28try to call assign role page question
  754. 35:29sees that and we can provide right here
  755. 35:32admin role variable and whenever the CD
  756. 35:36is executed it's going to create the
  757. 35:37user create the role and then assign the
  758. 35:40role to that user so let's bring up the
  759. 35:43terminal and I'm going to execute PHP
  760. 35:45Artisan
  761. 35:47nanometrate DB colon seed
  762. 35:50so seating database has been completed
  763. 35:52let's now open database then we have new
  764. 35:55admin user if we open roles we have
  765. 35:58admin role and if we check model has
  766. 36:03roles we're going to see that the model
  767. 36:06ID which is the currently added 11 ID
  768. 36:11user has role id1 okay so we defined
  769. 36:16those roles which is perfect
  770. 36:19now let's try to basically log in with
  771. 36:23the new user adminate example.com and
  772. 36:26let's let's just reload the page sign
  773. 36:30out and now I'm going to use admin at
  774. 36:33example.com
  775. 36:34admin123 and look at this so we are
  776. 36:38right now logged in as an admin user but
  777. 36:41actually if I try to log in with Mary
  778. 36:45let's use the auto compilation
  779. 36:49now we are still in the admin so we
  780. 36:51created role we created admin user but
  781. 36:53we haven't defined a restriction for
  782. 36:56normal users to the admin for this again
  783. 37:00we are going to open the user PHP and
  784. 37:02we're going to implement right here an
  785. 37:05interface called
  786. 37:07uh filament how is it called I just
  787. 37:10forgot filament user I think that's it
  788. 37:12filament user yes and we have a red
  789. 37:16underline right here this uh it comes
  790. 37:18from the PHP showroom it indicates that
  791. 37:20we need to implement a method from the
  792. 37:22straight so if we just hit the control
  793. 37:24and mouse on this filament user we see
  794. 37:26that it has the following following
  795. 37:29method defined and that is can access
  796. 37:32filament in phpstorm I can just hit alt
  797. 37:35and enter and this gives me a couple of
  798. 37:38options Aid method is tabs click OK and
  799. 37:42at the very bottom we're going to see
  800. 37:43this method can access filament and
  801. 37:46we're going to return true or false from
  802. 37:48here if I just return true basically
  803. 37:51every user will be able to access if I
  804. 37:53return false none of the users will be
  805. 37:56able to access so if I just reload now
  806. 37:59Mary is not be able to access even admin
  807. 38:01will not be able so we need some kind of
  808. 38:03condition right here okay so this has
  809. 38:06role we're going to call a method has
  810. 38:08roll
  811. 38:09excuse me has a role and specify the
  812. 38:13role name so only those users should be
  813. 38:16able to access that interface if the
  814. 38:20user basically has that specific role
  815. 38:24admin role in this case so if I just
  816. 38:26roll the page we are not able to access
  817. 38:29this so I'm going to inspect because I
  818. 38:32want to clear the session I'm going to
  819. 38:34go in the application uh cookies and I'm
  820. 38:37going to clear everything just reload
  821. 38:39the page and it redirects us to the
  822. 38:42login and we try to basically again let
  823. 38:46me actually try to log in with Mary we
  824. 38:48see permission forbidden but if I try to
  825. 38:52reload the website we are actually
  826. 38:55logged in with Mary and I can log out
  827. 38:57from here as well okay let me reload the
  828. 39:00page and now let's try to access with
  829. 39:02admin user
  830. 39:04admin hit the enter now we are able to
  831. 39:08access filament admin admin panel which
  832. 39:11is awesome so the admin users can create
  833. 39:13categories posts text Regis manage the
  834. 39:16content and normal users can log in on
  835. 39:19the website we haven't defined any any
  836. 39:21functionality which is relevant for the
  837. 39:24normal users which are optimized on the
  838. 39:26website but still we have the
  839. 39:28authentication implemented which is
  840. 39:30which is great
  841. 39:32here I have generated users resource so
  842. 39:36from admin I can manage users as well I
  843. 39:38think this is uh generated outside of
  844. 39:40the recording so you cannot find this
  845. 39:43actually in the first part but
  846. 39:45generating users resource is pretty
  847. 39:48identical generating post resource so I
  848. 39:50just did this because I needed users in
  849. 39:53the admin as well
  850. 39:55but the most important thing right here
  851. 39:57is that every user which is created
  852. 39:58right now from admin needs to have admin
  853. 40:02role okay if I just create new user it
  854. 40:05will not have admin role and this is
  855. 40:07something we are going to change so I'm
  856. 40:11going to go in the app filament and
  857. 40:15let's open user resource and open this
  858. 40:18create user right here and we have to
  859. 40:21customize this we have to add a new
  860. 40:24admin role to every user when that is
  861. 40:28actually created so right here I'm going
  862. 40:30to create create new function handle
  863. 40:33record creation which is a protected
  864. 40:36function and we can actually customize
  865. 40:38this this handle record creation if we
  866. 40:40just fold the follow this it gets the
  867. 40:44model based on the class and creates
  868. 40:45that so whenever this is called we can
  869. 40:49take these as already created user and
  870. 40:54say that in a very table right and we
  871. 40:56know that every user has that has that
  872. 41:01trait as roles so basically if I
  873. 41:07let's call in the create user so if I
  874. 41:09call on that user
  875. 41:13hold on if I call this a sign role again
  876. 41:16after completion doesn't work because
  877. 41:18PHP stream doesn't understand that this
  878. 41:20user is an instance of app modules user
  879. 41:22so I generally tend to Define this
  880. 41:24because I love when people store
  881. 41:26autocomposite for me it's also very easy
  882. 41:29if you want to search then in your
  883. 41:31entire project where are the instances
  884. 41:34of that user basically it will find that
  885. 41:37place as well if I just remove The
  886. 41:39annotation and go in the user PHP and
  887. 41:42right click on the class and try to find
  888. 41:44the usages of that class it will not
  889. 41:48find that specific
  890. 41:51alone that specific variable because it
  891. 41:54has no idea that this is an instance of
  892. 41:56app models user right if I add this
  893. 41:59annotation and then call this find
  894. 42:01usages then it will find end it's also
  895. 42:04good if you want to find out where you
  896. 42:06have all the instances of the specific
  897. 42:07specific model so in this case I'm going
  898. 42:10to try to call assign role on that and
  899. 42:13provide admin
  900. 42:15uh
  901. 42:16admin right here and finally we need to
  902. 42:19return user
  903. 42:23my keyboard
  904. 42:25I just don't like my keyboard I'm going
  905. 42:28to replace it
  906. 42:29okay so the user creation process is
  907. 42:32like this and if I now go in the admin
  908. 42:35and try to create
  909. 42:38new uh new user so let's call this shown
  910. 42:42let's give it
  911. 42:44Sean at example.com email verify that is
  912. 42:48something we can Skip and the password
  913. 42:50will be
  914. 42:52something secure okay and let's hit
  915. 42:55create
  916. 42:57uh let's hit never okay so the user was
  917. 43:00created now the most important thing is
  918. 43:02to go in the database check the database
  919. 43:05let's open users first we see that John
  920. 43:09is created with ID 12. and second is the
  921. 43:14model has rows let's open this and now
  922. 43:16we see that there is a rule one assigned
  923. 43:19to Model 12 okay however I think the
  924. 43:22user might not be able to log in because
  925. 43:24email verified is actually null and this
  926. 43:27is something we probably need to also
  927. 43:28fix let me actually try to sign out and
  928. 43:32try to log in with John
  929. 43:37yes I am not able to to log in now let's
  930. 43:40open users and I'm gonna let's actually
  931. 43:43try to log in with admin
  932. 43:48admin123
  933. 43:49okay good let's open users and we can
  934. 43:52edit this and provide
  935. 43:55uh provide some some value inside email
  936. 43:58verified it and whenever we do this this
  937. 44:01password is by the way required so this
  938. 44:03form is just a very very basic form I
  939. 44:06just generated as I mentioned outside of
  940. 44:07the recording I haven't customized that
  941. 44:09at all the password should not be
  942. 44:11required whenever we are updating the
  943. 44:14user password should be optional and
  944. 44:17even we should have probably two fields
  945. 44:20for the password password and password
  946. 44:21repeat so that if you want to change a
  947. 44:24password reset the password for a
  948. 44:25specific user you should be able to uh
  949. 44:28provide it you should provide it twice
  950. 44:30just to avoid any kind of mistakes so in
  951. 44:33this case for Simplicity I'm just going
  952. 44:34to provide from one to
  953. 44:37um
  954. 44:38from one two like whatever and hit save
  955. 44:42changes okay that was saved but now
  956. 44:45whenever we try to create new user this
  957. 44:48email verify that needs to be set
  958. 44:50automatically okay so let's customize
  959. 44:53this form
  960. 44:54and let's go in the where's that create
  961. 44:58user I know that is
  962. 45:05our resources
  963. 45:07user resource
  964. 45:10create where is the form
  965. 45:15down below here we see user resource
  966. 45:18okay and so this is the form uh we can
  967. 45:21completely remove this email verify that
  968. 45:23we don't need to provide this twice uh
  969. 45:27sorry we don't need to provide this at
  970. 45:29all we need to provide password probably
  971. 45:32twice let's remove required from here as
  972. 45:35well
  973. 45:36we can provide right here
  974. 45:39the method using which we can hide the
  975. 45:42password field when we are editing the
  976. 45:44user as well so like the password the
  977. 45:47input field is the password max length
  978. 45:49and let's provide right here that should
  979. 45:51be hidden on
  980. 45:54edit so we don't want this to be on edit
  981. 45:59however we can also provide that this
  982. 46:03needs to be visible
  983. 46:05visible on create
  984. 46:10so in this case we need to Define
  985. 46:12probably two password Fields let's do
  986. 46:14like this so the one password with the
  987. 46:16password max length this is hidden on
  988. 46:19edit
  989. 46:20let's select this and the second one
  990. 46:23is
  991. 46:25visible on Create and we can also
  992. 46:27specify right here required
  993. 46:31okay so that must be required and that
  994. 46:35is
  995. 46:36visible on create let's save this and
  996. 46:40have a look reload the page this is user
  997. 46:43creation so we see password actually
  998. 46:46twice which is something we shouldn't
  999. 46:49see
  1000. 46:50uh let's hide this on create as well
  1001. 46:57okay let's try to have this all in a
  1002. 46:59single input field password required not
  1003. 47:02the required a max length and then let's
  1004. 47:05just provide hidden on edit and then
  1005. 47:09provide required and visible oncreate
  1006. 47:12let's see if this gives us exactly what
  1007. 47:15we want
  1008. 47:17okay the password is still visible on
  1009. 47:20user creation that's correct so it
  1010. 47:22should be visible on user creation but
  1011. 47:24the interesting thing is update so if I
  1012. 47:26click update we don't see password Here
  1013. 47:30we choose
  1014. 47:32which is exactly what we wanted in this
  1015. 47:34case however as I mentioned if you want
  1016. 47:37to reset the user password you won't be
  1017. 47:39actually be able to do this
  1018. 47:42so in this case I'm going to add one
  1019. 47:45more method
  1020. 47:46and that will be confirmed so the
  1021. 47:50password needs to be confirmed and we
  1022. 47:53need a second field for password
  1023. 47:55confirmation as well and let's give it
  1024. 47:58the proper name confirmation
  1025. 48:01all right and the password confirmation
  1026. 48:03also needs to be visible on let's
  1027. 48:07actually take this part
  1028. 48:13so it's a password max length hidden on
  1029. 48:16edit required visible on create blah
  1030. 48:19blah let's now reload the page
  1031. 48:22on edit we don't see that
  1032. 48:24uh let's that was actually View
  1033. 48:28I want to submit this form just make
  1034. 48:30sure that even though we just we don't
  1035. 48:33display it it is not required we have
  1036. 48:35this required function here so click on
  1037. 48:37save that was actually saved perfect uh
  1038. 48:40if we go in the users we see John 2 that
  1039. 48:43was updated now a new we have password
  1040. 48:46and password confirmation let's create
  1041. 48:48Tom for example
  1042. 48:51we provide password if I don't provide
  1043. 48:55the password confirmation and hit create
  1044. 48:58we get this error if I provide incorrect
  1045. 49:01password click create we get this error
  1046. 49:04perfect
  1047. 49:05so now we have possibility to
  1048. 49:08we have possibility to set the password
  1049. 49:12of the user
  1050. 49:13okay did I make any mistake
  1051. 49:16let's provide password properly
  1052. 49:21password confirmation field doesn't
  1053. 49:24okay that looks like
  1054. 49:27we don't have it as we should have so
  1055. 49:31the password
  1056. 49:32is password max length in required and
  1057. 49:35it is confirmed password confirmation
  1058. 49:41okay great again let's provide password
  1059. 49:49hit create it doesn't seem to be working
  1060. 49:53okay let's check the source code and I
  1061. 49:58think that is the problem it's a stupid
  1062. 49:59mistake so password confirmation
  1063. 50:01obviously doesn't need confirmed role
  1064. 50:04the confirmed rule is necessary on the
  1065. 50:07password itself so if I save this and
  1066. 50:10hit create now the user was created so
  1067. 50:14that's perfect however speaking of the
  1068. 50:16email verify that that is still null for
  1069. 50:19every new user so let's just open that
  1070. 50:21create user
  1071. 50:24and maybe before before the user is
  1072. 50:28created inside the data we can provide
  1073. 50:31email verified
  1074. 50:34it
  1075. 50:35is just current time
  1076. 50:38let's provide
  1077. 50:40time here or I think we can provide
  1078. 50:43carbon now as well so I save this
  1079. 50:48now let's try to add new user
  1080. 50:51Let It Be Gene in this case
  1081. 50:54and gym
  1082. 50:59and let's provide password
  1083. 51:05at the end okay password confirmation
  1084. 51:08does not match
  1085. 51:11hit create
  1086. 51:15okay email verify that was not saved
  1087. 51:20okay we can we can create another method
  1088. 51:23which just like we did in the post
  1089. 51:24resource if we
  1090. 51:27open these post resource here
  1091. 51:31note here sorry right here in this post
  1092. 51:35resource we have these create post and
  1093. 51:38we have this mutated form data before
  1094. 51:40create okay so we just copy this and go
  1095. 51:44in the create user and let me paste this
  1096. 51:48here and mutate form data before create
  1097. 51:51we provide
  1098. 51:53email verify that and let's provide
  1099. 51:56carbon now
  1100. 51:58let's remove this from here I save it
  1101. 52:01and let's try to add new user let's give
  1102. 52:05it test in this case
  1103. 52:08let's give it short password click
  1104. 52:10create
  1105. 52:12okay email verified it is still and not
  1106. 52:15provided
  1107. 52:17and
  1108. 52:19I think the reason might be that this is
  1109. 52:23excluded and not provided in the
  1110. 52:26fillable
  1111. 52:28and that is added in the casts so we
  1112. 52:31need to add this in the fillable and
  1113. 52:34then it will work
  1114. 52:36let's try to add new user
  1115. 52:38S2
  1116. 52:41let's provide short password click
  1117. 52:44create and this worked this time so now
  1118. 52:47we have this test user which has even
  1119. 52:49verified it and this is admin user by
  1120. 52:52the way and if I now try to sign out and
  1121. 52:56try to log in with the test two let's
  1122. 52:59try to log in first with the test
  1123. 53:02it doesn't work because the email is not
  1124. 53:05verified but now if I try to log in with
  1125. 53:07test2
  1126. 53:09okay it doesn't work
  1127. 53:11either
  1128. 53:13and I think the reason might be that the
  1129. 53:15password
  1130. 53:17is it saved properly let's check this
  1131. 53:20not sure the passwords are saved and
  1132. 53:23passwords are saved as plain text
  1133. 53:24obviously we haven't implemented this
  1134. 53:27part so if we open user resource uh not
  1135. 53:30the user resource but create user
  1136. 53:33and right here mutate form data before
  1137. 53:36create
  1138. 53:37so we want to
  1139. 53:40hash the password before create so we're
  1140. 53:43going to call Big creeped here
  1141. 53:46and
  1142. 53:47then we provide a data password
  1143. 53:52just like this
  1144. 53:54now let's create test three in this case
  1145. 53:57we need to log in with admin
  1146. 54:00please try again three seconds okay
  1147. 54:04one two three
  1148. 54:06now let's go in users and let's create
  1149. 54:11and by the way that was an extra
  1150. 54:13security of filament which I liked so if
  1151. 54:16you try too many attempts incorrect
  1152. 54:18attempts then it tells you to wait
  1153. 54:20that's I think
  1154. 54:23really good let's create now one more
  1155. 54:26user
  1156. 54:27in this case the password encryption
  1157. 54:30should work
  1158. 54:31hit create okay it doesn't work let's
  1159. 54:34give it short password
  1160. 54:36okay so we have that now let's check the
  1161. 54:40database first
  1162. 54:42okay here we see encrypted password now
  1163. 54:45let's sign out
  1164. 54:47and try to sign in and that works this
  1165. 54:50time okay now every user which is
  1166. 54:53Created from filament admin is an admin
  1167. 54:56user and the password the email is
  1168. 54:58verified and password is encrypted and I
  1169. 55:01guess we can delete all the previous
  1170. 55:03users because their passwords are not
  1171. 55:05encrypted okay now I'm going to
  1172. 55:08implement one very important and really
  1173. 55:11cool feature and there's going to be
  1174. 55:12upvote and download of Articles every
  1175. 55:16authorized user will have this ability
  1176. 55:17to click a button and upvote article and
  1177. 55:21give a credit to the article and in the
  1178. 55:24future maybe based on the number of
  1179. 55:25apples on certain article we can promote
  1180. 55:28that and show on the home page or
  1181. 55:30showing recommended articles and do some
  1182. 55:33things like that so let's start
  1183. 55:36implementing this really cool feature
  1184. 55:37and I'm going to do this using laravel
  1185. 55:40Live Wire
  1186. 55:42uh filament PHP behind actually is using
  1187. 55:45whatever Live Wire but we haven't used
  1188. 55:48on the front end it at all so I'm going
  1189. 55:51to open the documentation a live wire
  1190. 55:54and let's have a look
  1191. 55:56so let's go in the docs and I'm gonna
  1192. 55:59like um give you a quick overview so
  1193. 56:02right here you can find the
  1194. 56:03documentation let's click on install
  1195. 56:06Live Wire we need to run composer
  1196. 56:08require but as I mentioned because we
  1197. 56:10already have a filament PHP which
  1198. 56:12internally uses a lot of a live wire we
  1199. 56:15can skip that section and we can just
  1200. 56:18import that live wire Styles and scripts
  1201. 56:20in our layout just to make sure we have
  1202. 56:23Live Wire installed let's open our
  1203. 56:25project
  1204. 56:27let's open composer composer log file
  1205. 56:31and inside there let's search for
  1206. 56:33Livewire and if we see that in somewhere
  1207. 56:36as a dependency it means that it is
  1208. 56:38included and if we see if we check the
  1209. 56:40package uh that is Livewire late rate
  1210. 56:45limiter and the live wires dependency of
  1211. 56:49it and if we just follow that and find
  1212. 56:51out internally it's going to be finally
  1213. 56:54a dependency of filament PHP okay
  1214. 56:58so we already have Live Wire installed
  1215. 57:01now we need to register Styles and
  1216. 57:04scripts in our application so I'm going
  1217. 57:06to open layout up blade PHP and in the
  1218. 57:11header let's do this before white let's
  1219. 57:15include the Styles and at the very
  1220. 57:17bottom they are like a before the
  1221. 57:20closing of the body tag I'm going to
  1222. 57:23include Live Wire Scripts
  1223. 57:26okay so far so good and then having a
  1224. 57:29look at the quick start we can already
  1225. 57:31generate a component so in this case I'm
  1226. 57:34going to call my component let's start a
  1227. 57:39new terminal vendor being sale Bash
  1228. 57:44all right and now let's generate a live
  1229. 57:47wire component and I'm going to call
  1230. 57:49this upfold download component okay
  1231. 57:52that's going to be like your two buttons
  1232. 57:54uh hands up thumbs up and thumbs down
  1233. 57:57and yeah just like this we're going to
  1234. 58:00show number of upvotes in number of down
  1235. 58:02rules on a particular article so let's
  1236. 58:06click enter right here right so it asks
  1237. 58:09me whether I want to start the Ripple or
  1238. 58:11not I have actually already started it
  1239. 58:13so I'm going to type a no right here so
  1240. 58:16the Live Wire component was actually
  1241. 58:18generated and if we open up
  1242. 58:21HTTP Live Wire we see this apple
  1243. 58:24download there's a very basic Live Wire
  1244. 58:26component and it renders the following
  1245. 58:28view file and that view file already
  1246. 58:32exists upvote Dash download play there's
  1247. 58:36an empty blade file okay so we have this
  1248. 58:39Live Wire component but now let's focus
  1249. 58:42on the database right so we need the uh
  1250. 58:46actually before we do the database let's
  1251. 58:49put some something right here like a
  1252. 58:51test and then let's open view file
  1253. 58:56there's going to be the article
  1254. 58:58interview and inside that inside that
  1255. 59:02white background card
  1256. 59:07at the very bottom maybe we can use Live
  1257. 59:10Wire colon and the component name in
  1258. 59:15this case it's going to be upfold down
  1259. 59:17vote that's going to be the component
  1260. 59:19all right so I save this I think we need
  1261. 59:24Dash right here upload Dash download so
  1262. 59:27I save this and now let's open the
  1263. 59:29front-end side and click on the very
  1264. 59:30first article we are in the inner page
  1265. 59:32then right here we see test okay so the
  1266. 59:34Live Wire component is actually rendered
  1267. 59:36from here now let's focus on the
  1268. 59:38database because we're going to save
  1269. 59:39this app volts and downloads in the
  1270. 59:42database
  1271. 59:43I'm going to generate new model and
  1272. 59:45migration HP artisan make model upvote
  1273. 59:51download let's call this same name as
  1274. 59:54the component and dash M we need this as
  1275. 59:57well now let's open migration file
  1276. 1:00:03right here and let's define few Fields
  1277. 1:00:06like first I'm going to define a Boolean
  1278. 1:00:08type of field and it's going to be ease
  1279. 1:00:10upvote
  1280. 1:00:12okay so if this will be true it means
  1281. 1:00:16that user hit the upvote button if this
  1282. 1:00:19will be false it means user hit the
  1283. 1:00:21download button at the same time user
  1284. 1:00:23cannot hit upvote and download buttons
  1285. 1:00:26on the same article so it's going to be
  1286. 1:00:28either port or download so this is how
  1287. 1:00:31I'm gonna do this and we'll also provide
  1288. 1:00:34right here two foreign IDs
  1289. 1:00:37uh one will be post ID on which post the
  1290. 1:00:41upvote or download happens that
  1291. 1:00:44references to ID on table hosts and we
  1292. 1:00:49can also specify
  1293. 1:00:51um own delete what should happen on
  1294. 1:00:53delete uh Cascade let's provide Cascade
  1295. 1:00:56here I'm going to duplicate this same
  1296. 1:00:58line and it will also provide the user
  1297. 1:01:01ID who made this upfold or download the
  1298. 1:01:05table will be users and we can leave
  1299. 1:01:07this Cascade so it is as simple as that
  1300. 1:01:10migration migration excuse me is ready
  1301. 1:01:13now let's open Terminal and execute PHP
  1302. 1:01:17Artisan migrate
  1303. 1:01:19okay the migration was applied and if we
  1304. 1:01:22check the database we are going to see
  1305. 1:01:25down below upload downloads table
  1306. 1:01:27perfect let's open up vote download uh
  1307. 1:01:32we need model
  1308. 1:01:34upvote download
  1309. 1:01:36and inside fillable let's add those
  1310. 1:01:41three Fields is up fold
  1311. 1:01:45we need post ID
  1312. 1:01:48and we need user ID
  1313. 1:01:51all right
  1314. 1:01:52so far so good now let's open this
  1315. 1:01:55upload download Livewire component and
  1316. 1:01:58in the render we are going to select how
  1317. 1:02:02many apples and how many downloads these
  1318. 1:02:05particular article has but we don't have
  1319. 1:02:07any identifier for this particular
  1320. 1:02:10article so what we are going to do
  1321. 1:02:13uh this upper blade I think we can close
  1322. 1:02:16this I'm going to close Ian as well I
  1323. 1:02:19will only leave those files which is
  1324. 1:02:20relevant for me at the moment I'm going
  1325. 1:02:22to close the migration as well inside
  1326. 1:02:24the view so from here I'm going to
  1327. 1:02:26provide post so that's going to be the
  1328. 1:02:29actual post on which we're going to show
  1329. 1:02:32up for it and download we're going to
  1330. 1:02:34accept that post variable
  1331. 1:02:36inside the Live Wire component like
  1332. 1:02:41here
  1333. 1:02:42we're going to create a mount function
  1334. 1:02:44in the mount function will accept this
  1335. 1:02:48post
  1336. 1:02:49first we need to import this post model
  1337. 1:02:52here then I'm going to create uh
  1338. 1:02:56oblique
  1339. 1:02:57host variable and
  1340. 1:03:01public and then this
  1341. 1:03:06host will be given post
  1342. 1:03:08all right and now here inside render I
  1343. 1:03:11have access to this post and I can
  1344. 1:03:13select how many upvotes or downloads
  1345. 1:03:16these post has but let's uh first to the
  1346. 1:03:19front-end side and I'm going to now open
  1347. 1:03:23hero icons which is a like SVG icons
  1348. 1:03:27really easy to use we're just gonna look
  1349. 1:03:30for
  1350. 1:03:32thumbs up or something like this here we
  1351. 1:03:34have those two icons and we just need
  1352. 1:03:36svgs there's like a no need to install
  1353. 1:03:39or require any CSS or anything we just
  1354. 1:03:42can copy SVG files and let's open this
  1355. 1:03:45up for download and I'm going to create
  1356. 1:03:47two buttons and that's going to be for
  1357. 1:03:50upvote so I'm going to paste this here
  1358. 1:03:53and the second button will be for
  1359. 1:03:56download let's copy SVG and paste this
  1360. 1:04:00here
  1361. 1:04:01all right so that's perfect now let's
  1362. 1:04:05add couple of CSS classes to those
  1363. 1:04:08buttons as well
  1364. 1:04:11so we're going to give it display flex
  1365. 1:04:13and items same term I'm going to give it
  1366. 1:04:16also Gap two uh and let's give it also
  1367. 1:04:20on Hover the text should be text blue
  1368. 1:04:24like a 500 and let's give it also a
  1369. 1:04:28transition all to have this nice effect
  1370. 1:04:31on Mouse over and right here and here we
  1371. 1:04:34are going to Output two variables number
  1372. 1:04:37of upvotes and number of downvotes
  1373. 1:04:40down below we need down volts and we
  1374. 1:04:44need to pass these two variables from
  1375. 1:04:47the Live Wire component into blade file
  1376. 1:04:51so I think we don't need this model I'm
  1377. 1:04:54going to close that and let's open the
  1378. 1:04:55component and there are two ways to pass
  1379. 1:04:59data from Live Wire component to Blade
  1380. 1:05:03file one is to declare that variable as
  1381. 1:05:06a public property of the class and then
  1382. 1:05:08can this can be accessed inside the
  1383. 1:05:10blade file in this case if we want to
  1384. 1:05:13access post we can access easily from
  1385. 1:05:15these view blade file the second
  1386. 1:05:18approach is to pass these two variables
  1387. 1:05:21in a view so this is what I'm gonna do
  1388. 1:05:24and I like second approach because
  1389. 1:05:26whenever something is changed in a
  1390. 1:05:28component like even Handler is triggered
  1391. 1:05:31or some sort of data is updated
  1392. 1:05:35then this render method is called and
  1393. 1:05:39the if we select some kind of data then
  1394. 1:05:42the view also will be called and view
  1395. 1:05:45will be updated very easily okay so now
  1396. 1:05:48let's select up folds and that's going
  1397. 1:05:51to be Apple download from modal we're
  1398. 1:05:54going to run where
  1399. 1:05:56host ID
  1400. 1:05:58equals to this
  1401. 1:06:01host ID and we are going to we're going
  1402. 1:06:07to add another weird
  1403. 1:06:09where
  1404. 1:06:10is upvote
  1405. 1:06:13equals one or true
  1406. 1:06:16and finally we're going to call count
  1407. 1:06:19okay so this will be number of upfolds
  1408. 1:06:23uh that has been made on that particular
  1409. 1:06:27post uh we can move this where and count
  1410. 1:06:31down to make it like more readable so
  1411. 1:06:34I'm going to duplicate this and the
  1412. 1:06:36second one will be downloads
  1413. 1:06:39and right here we're going to provide
  1414. 1:06:41false number of downwards on that
  1415. 1:06:45particular article okay so that's
  1416. 1:06:47perfect now let's provide right here
  1417. 1:06:49compact
  1418. 1:06:51up Folds and downloads now I'm Gonna
  1419. 1:06:56Save this and let's test this so far
  1420. 1:06:59let's open the front and side and
  1421. 1:07:02we have our basically let's reload okay
  1422. 1:07:06there is gone and at the very bottom we
  1423. 1:07:08have these two buttons with a zero okay
  1424. 1:07:11let's give
  1425. 1:07:13small CSS classes here let's give it
  1426. 1:07:16flex and gap of two
  1427. 1:07:19okay perfect we have up folding download
  1428. 1:07:21the how over effect works as well
  1429. 1:07:24now let's Implement actually clicking on
  1430. 1:07:26that button let's call the inner
  1431. 1:07:29component and I'm going to create a
  1432. 1:07:33component sorry I'm going to create a
  1433. 1:07:36method let's call this upfold download
  1434. 1:07:42okay so this method will be called
  1435. 1:07:44whenever user clicks on app Vote or on
  1436. 1:07:46download and actually I'm going to
  1437. 1:07:48accept a parameter right here whether
  1438. 1:07:50this is an upfold or download
  1439. 1:07:53so why I'm doing this as a single method
  1440. 1:07:56and not two separate methods like up
  1441. 1:07:58fold is a separate method in download as
  1442. 1:08:00a separate method because we're going to
  1443. 1:08:03have very similar logic in those both
  1444. 1:08:07methods if we're going to do it
  1445. 1:08:09separately and I don't like code
  1446. 1:08:11duplication so that's why I prefer to
  1447. 1:08:14write a dry code and just give a
  1448. 1:08:17parameter right here okay and calling
  1449. 1:08:20this up for download method from the
  1450. 1:08:23component from the blade file will be
  1451. 1:08:25super easy we just provide right here
  1452. 1:08:28wire colon
  1453. 1:08:30uh Clique that's the event name and
  1454. 1:08:34upvote download and then we can provide
  1455. 1:08:37the argument okay by default the
  1456. 1:08:39argument is true so we can provide only
  1457. 1:08:43false right here if we don't want it to
  1458. 1:08:45be upvote if we want it to be download
  1459. 1:08:48right so so far so good but in order to
  1460. 1:08:52upvote or download to happen the user
  1461. 1:08:56needs to be authorized right so we can
  1462. 1:09:00check if the user is authorized Android
  1463. 1:09:02direct to login page but first i'm going
  1464. 1:09:04to actually get the user because if the
  1465. 1:09:06user is authorized I need to access the
  1466. 1:09:09user information in any case so I'm
  1467. 1:09:13going to call request user
  1468. 1:09:17so I'm going to get the current user and
  1469. 1:09:19I'm going to add also annotation this is
  1470. 1:09:21an instance of app modules user because
  1471. 1:09:23uh like I really like to do this in
  1472. 1:09:27terms of I need some kind of Auto
  1473. 1:09:28completion or things like that then this
  1474. 1:09:31works excellent so if the user does not
  1475. 1:09:34exist we are going to Simply return from
  1476. 1:09:37here and let's call this redirect we're
  1477. 1:09:40going to redirect user to a login login
  1478. 1:09:43page okay
  1479. 1:09:46however if the user exists there is one
  1480. 1:09:49additional check to do if the email is
  1481. 1:09:52verified for that user okay and this is
  1482. 1:09:54the case where Auto completion works
  1483. 1:09:57perfectly because I added the sanitation
  1484. 1:09:59right here so if the user has a verified
  1485. 1:10:03email here more more correctly if the
  1486. 1:10:06user doesn't have a verified email we
  1487. 1:10:09are going to return
  1488. 1:10:11hold on return
  1489. 1:10:13these redirect
  1490. 1:10:16oops
  1491. 1:10:18and in this case I'm going to provide
  1492. 1:10:19the road function and pass the actual
  1493. 1:10:22Road name where the redirect user to the
  1494. 1:10:26um like email verification page and if
  1495. 1:10:29we open now out PHP from the roles which
  1496. 1:10:32is generated by lateral Breeze and
  1497. 1:10:35scroll down below we should see this
  1498. 1:10:37verify email URL with verification
  1499. 1:10:41notice name Road name so this is the
  1500. 1:10:44road name we're going to use in this
  1501. 1:10:46case so I'm going to provide it right
  1502. 1:10:48here
  1503. 1:10:49okay so and at the very bottom it means
  1504. 1:10:52that the user is successfully
  1505. 1:10:54authenticated on the website and the
  1506. 1:10:57email also is verified so now we are
  1507. 1:11:00going to Simply
  1508. 1:11:01um
  1509. 1:11:02make a record in the database or if the
  1510. 1:11:05record already exists we're going to
  1511. 1:11:07delete that record so first let's select
  1512. 1:11:10if there already exists Apple download
  1513. 1:11:13record uh in the database
  1514. 1:11:16so let's select upvote download equals
  1515. 1:11:20that's going to be
  1516. 1:11:22from the model let's write weird
  1517. 1:11:25for that specific post post ID
  1518. 1:11:29underscore ID equals to this host ID
  1519. 1:11:34okay we need another where in this case
  1520. 1:11:38we're going to provide user ID we are
  1521. 1:11:40interested if there is upvote or
  1522. 1:11:43download for that specific user these
  1523. 1:11:46are not this in this case we just need
  1524. 1:11:48user ID
  1525. 1:11:50okay so we select that and we just need
  1526. 1:11:53to get our first record
  1527. 1:11:57from here now if this does not exist
  1528. 1:12:01there's no upvote download record then
  1529. 1:12:05we're going to do the following so we're
  1530. 1:12:07going to create new record
  1531. 1:12:09upload download create
  1532. 1:12:12and we are going to pass is up Folds
  1533. 1:12:19excuse me
  1534. 1:12:22is up fold will be the given parameter
  1535. 1:12:24whether we are doing upvote or download
  1536. 1:12:28we're going to provide post ID
  1537. 1:12:32this
  1538. 1:12:34host ID and we're going to provide user
  1539. 1:12:38ID
  1540. 1:12:40as well
  1541. 1:12:42user ID
  1542. 1:12:45okay that's perfect and I think we can
  1543. 1:12:49return and don't continue anything below
  1544. 1:12:51from here
  1545. 1:12:53then if the app will download already
  1546. 1:12:56exists we're gonna do two things like if
  1547. 1:13:01the user is clicking upload button
  1548. 1:13:04then we're going to check if the record
  1549. 1:13:07which exists in the database is
  1550. 1:13:09for up fault
  1551. 1:13:12we are going to delete that record
  1552. 1:13:15completely
  1553. 1:13:17okay
  1554. 1:13:20so let's check if
  1555. 1:13:23the action what we're going to do is
  1556. 1:13:26upvote and the record up for download
  1557. 1:13:30maybe that's a confusing let's call this
  1558. 1:13:32model okay I'm going to rename this and
  1559. 1:13:34call this model
  1560. 1:13:35that's a database model if the model in
  1561. 1:13:38the database has is upvote
  1562. 1:13:42so if we are doing upvote but in the
  1563. 1:13:44database there is already up for type of
  1564. 1:13:47record simply we are going to delete the
  1565. 1:13:50model okay it means that user wants to
  1566. 1:13:53remove his app vote simply take back his
  1567. 1:13:57upvote
  1568. 1:13:59we're going to do an else statement as
  1569. 1:14:01well if this is not the case uh then uh
  1570. 1:14:06okay let me first do another if right
  1571. 1:14:09here and then we can the the else case
  1572. 1:14:11will be very straightforward okay so if
  1573. 1:14:14user is doing upload in the model
  1574. 1:14:16um already has upload we delete that or
  1575. 1:14:19there's another case if the user
  1576. 1:14:22wants download
  1577. 1:14:24and model
  1578. 1:14:29already has download is
  1579. 1:14:33upvote equals false okay in this case we
  1580. 1:14:37do the same thing like if the user has
  1581. 1:14:39previously hit the download button and
  1582. 1:14:41let's call it dislike this is I think
  1583. 1:14:44very easy to say so if the user
  1584. 1:14:45previously disliked the article it now
  1585. 1:14:49wants to remove the dislike then we
  1586. 1:14:52delete that so in this case we have
  1587. 1:14:55model and in model we specify is upvote
  1588. 1:15:02equals whatever is given upload
  1589. 1:15:07okay
  1590. 1:15:08so this is what we are going to do and
  1591. 1:15:10then on model
  1592. 1:15:13we are going to call Save
  1593. 1:15:16so this will update the existing upvote
  1594. 1:15:19download record and whenever this is
  1595. 1:15:22executed this function is executed and
  1596. 1:15:25because this makes some like
  1597. 1:15:27modifications in the database as well
  1598. 1:15:30the re-render method will be executed
  1599. 1:15:33and the the selects will run and the
  1600. 1:15:37counts of each of the items will be
  1601. 1:15:40already modified
  1602. 1:15:42so if you don't believe me let's reload
  1603. 1:15:44the page and click upvote and as you see
  1604. 1:15:47right here we see one if I just roll the
  1605. 1:15:50page one is there so record was
  1606. 1:15:53successfully made in the database now if
  1607. 1:15:55I click upvote again it removes the
  1608. 1:15:57upfold and now we see Zero again now
  1609. 1:16:00let's click download we see Zero click
  1610. 1:16:03download again sorry we saw one and now
  1611. 1:16:07we see Zero now if I click up vote and
  1612. 1:16:10then I click download then look at this
  1613. 1:16:13so it actually worked properly it
  1614. 1:16:15changed existing upload record into
  1615. 1:16:18download
  1616. 1:16:20so I think that works excellent and that
  1617. 1:16:23works exactly as I want except that I'm
  1618. 1:16:25going to add one additional thing
  1619. 1:16:28if the currently authorized user has
  1620. 1:16:31this particular article upvoted we're
  1621. 1:16:34going to show this button blue
  1622. 1:16:36so we're going to do this in the render
  1623. 1:16:38method and I'm going to Define a
  1624. 1:16:40variable here has upvote
  1625. 1:16:44and I'm gonna also add a comment right
  1626. 1:16:47here which perfectly describes what this
  1627. 1:16:50variable should do so that's going to be
  1628. 1:16:52the status whether the current user has
  1629. 1:16:54upvoted the post uh or not and this
  1630. 1:16:57might be now true or false if it's null
  1631. 1:17:00it means that user has not taken any
  1632. 1:17:03action has not upvoted or
  1633. 1:17:06downvoted that article if it's a true
  1634. 1:17:09user upvoted if it's false user
  1635. 1:17:12downloaded that particular article okay
  1636. 1:17:16I'm going to query also a user let me
  1637. 1:17:18actually grab this from here
  1638. 1:17:20I need the current user and I'm going to
  1639. 1:17:23make a query in the database first I'm
  1640. 1:17:26going to check if the user is authorized
  1641. 1:17:29if that exists then let's actually
  1642. 1:17:32select a variable from the up for
  1643. 1:17:35download we can call this model or
  1644. 1:17:37current status let's call this model
  1645. 1:17:39okay
  1646. 1:17:41model equals upvote download where
  1647. 1:17:47provide post ID
  1648. 1:17:49equals
  1649. 1:17:52this host ID and we also provide the
  1650. 1:17:58user ID
  1651. 1:18:03user ID and we just select the very
  1652. 1:18:08first record
  1653. 1:18:10all right let's move this where in first
  1654. 1:18:14down so we select the very first item
  1655. 1:18:17for this particular user and the um for
  1656. 1:18:21this particular post and now we're gonna
  1657. 1:18:24check if the model exists so if there's
  1658. 1:18:27a adap photo download for that specific
  1659. 1:18:30model then his upvote basically equals
  1660. 1:18:34whatever is the models is upvote
  1661. 1:18:40okay
  1662. 1:18:41but I'm going to add right here double
  1663. 1:18:43exclamation
  1664. 1:18:45just because this is up fold will return
  1665. 1:18:48true uh not true uh it will return one
  1666. 1:18:51or zero because the database will hold
  1667. 1:18:54the values into one and zero for Boolean
  1668. 1:18:57mySQL database and using this double
  1669. 1:19:00exclamation we're converting this into
  1670. 1:19:02an actual Boolean and now in this view
  1671. 1:19:05we can pass his upvote and now let's
  1672. 1:19:10open this upvote download blade PHP and
  1673. 1:19:13I'm going to add CSS classes so first
  1674. 1:19:16right here
  1675. 1:19:17his upfruit
  1676. 1:19:19if that has upfold exists so if if it's
  1677. 1:19:25a chewable value so it will internally
  1678. 1:19:28be true actually if this is true then uh
  1679. 1:19:33we don't need actually hover anymore but
  1680. 1:19:35we can leave that but we're going to
  1681. 1:19:38directly make the color blue 500 right
  1682. 1:19:43so let's do like this and in else simply
  1683. 1:19:47we don't add anything let's make on
  1684. 1:19:49however it uh like a 600 let's do like
  1685. 1:19:52this and in the downward button we do
  1686. 1:19:55the same thing very similar thing
  1687. 1:19:58however if the upvote equals false okay
  1688. 1:20:03I don't want to type if not upvote
  1689. 1:20:06because that's tricky null is also not
  1690. 1:20:11has upvote so if the hazard for this
  1691. 1:20:14null then this will be also satisfied
  1692. 1:20:16that's why I want to explicitly check if
  1693. 1:20:19it has upvote is equals false with three
  1694. 1:20:23equality because
  1695. 1:20:25right here we're going to have false so
  1696. 1:20:28in this case I add the text blue 500
  1697. 1:20:30right here otherwise we had an empty
  1698. 1:20:32class let's change this into 600 let's
  1699. 1:20:35save this reload the page
  1700. 1:20:38and voila we see this upfold pattern
  1701. 1:20:41blue if I Mouse over it slightly changes
  1702. 1:20:44the color because it's uh now on Hover
  1703. 1:20:46we have 600. if I click on the download
  1704. 1:20:49then this button becomes blue so that's
  1705. 1:20:52a perfect indicator for me as a user
  1706. 1:20:56that I have once upvoted that particular
  1707. 1:21:00article which is which is awesome now
  1708. 1:21:03I'm going to do one small fix
  1709. 1:21:06so right here we don't see the previous
  1710. 1:21:08pattern but actually if we click next
  1711. 1:21:11and keep clicking next finally we're
  1712. 1:21:15going to reach the end where there are
  1713. 1:21:17no more articles and in this case
  1714. 1:21:20there will be a problem so in this view
  1715. 1:21:23blade we check if the previous exists
  1716. 1:21:25then we render the previous button
  1717. 1:21:28and if it doesn't exist simply this is
  1718. 1:21:31not rendered however we don't do the
  1719. 1:21:33same check for the next button so as
  1720. 1:21:36simple as that like let's copy this if
  1721. 1:21:39statement and change this prev into next
  1722. 1:21:43and then right here we need end if
  1723. 1:21:47so we format the code and if the next
  1724. 1:21:50exists we render that if it doesn't
  1725. 1:21:52exist we don't render that and it's as
  1726. 1:21:54simple as that now let's start working
  1727. 1:21:56to save views for each article whenever
  1728. 1:21:59user opens an article we're going to
  1729. 1:22:01save that and probably also save a user
  1730. 1:22:04ID maybe IP addresses as well as the
  1731. 1:22:07user agent so we have a little bit of
  1732. 1:22:09information from which location users
  1733. 1:22:12are checking our posts as well as from
  1734. 1:22:14which browsers they're actually doing
  1735. 1:22:16this so it's going to be good good to
  1736. 1:22:18save so we're going to create migration
  1737. 1:22:20save post views and then in the admin
  1738. 1:22:23panel we're going to display for each
  1739. 1:22:24article how many views that article gets
  1740. 1:22:27and later we can also Implement to sort
  1741. 1:22:29the top particles or posts by their
  1742. 1:22:34number of views right
  1743. 1:22:36so I think it's going to be pretty
  1744. 1:22:37interesting so I'm going to open
  1745. 1:22:38phpstorm first I'm going to bring up the
  1746. 1:22:42terminal and I'm going to create
  1747. 1:22:43migration PHP artisan make I'm going to
  1748. 1:22:48create model post to view and I'm going
  1749. 1:22:50to generate migration as well now let's
  1750. 1:22:52open create post migration
  1751. 1:22:56not this one but create post create post
  1752. 1:23:00views actually so we need to Define two
  1753. 1:23:04columns right here so string
  1754. 1:23:08uh one will be IP address and let's give
  1755. 1:23:11it a length of 55. I'm going to Define
  1756. 1:23:13also user agent let's give it a length
  1757. 1:23:18of 205 I'm going to Define our foreign
  1758. 1:23:22ID for post table according ID post ID
  1759. 1:23:25that has constrained
  1760. 1:23:30constrained on post table and I'm going
  1761. 1:23:34to duplicate this basically right here
  1762. 1:23:35in this constraint method you can
  1763. 1:23:36specify the table name however if you
  1764. 1:23:39don't specify it's gonna a lot of it
  1765. 1:23:41will assume that there's a posts table
  1766. 1:23:44based on the column name
  1767. 1:23:46and we can specify here user ID as well
  1768. 1:23:49but the user ID actually should be
  1769. 1:23:51nullable because
  1770. 1:23:52unauthorized users might also be
  1771. 1:23:55checking articles right
  1772. 1:23:57so I'm going to save these now let's
  1773. 1:24:00open post view model and right here I'm
  1774. 1:24:04going to define a fillable
  1775. 1:24:07with these four columns so I'm gonna
  1776. 1:24:11just copy them paste here
  1777. 1:24:16let's
  1778. 1:24:17save everything let's semicolon all
  1779. 1:24:19right now we have modal and migration
  1780. 1:24:21ready now I'm going to bring up the
  1781. 1:24:23terminal and execute PHP Artisan migrate
  1782. 1:24:27all right now we have this table ready
  1783. 1:24:30and let's open
  1784. 1:24:32post controller
  1785. 1:24:36and we're going to check uh show method
  1786. 1:24:39where we're going to see one specific
  1787. 1:24:41post and right here we are going to
  1788. 1:24:45maybe
  1789. 1:24:47First Take request
  1790. 1:24:50then down below from that request we are
  1791. 1:24:54going to get currently authorized user
  1792. 1:24:58and then we're gonna run host view
  1793. 1:25:01create
  1794. 1:25:03so we're going to create a postview
  1795. 1:25:05record we're going to specify IP address
  1796. 1:25:09and we're going to get these from
  1797. 1:25:11request IP method we are going to
  1798. 1:25:14specify user agent
  1799. 1:25:17we get this from request
  1800. 1:25:20user agent and we're going to specify
  1801. 1:25:23also post ID
  1802. 1:25:26which will be current post ID and user
  1803. 1:25:31ID as well and that's going to be
  1804. 1:25:33current a user
  1805. 1:25:36but I'm going to use a question mark
  1806. 1:25:37Arrow here because the user might be now
  1807. 1:25:41and then specify ID right here so this
  1808. 1:25:43will basically return null if the user
  1809. 1:25:45is now
  1810. 1:25:46and it's gonna it's not gonna throw an
  1811. 1:25:49error so I save this and now let's open
  1812. 1:25:52website and we are on specific article
  1813. 1:25:55page and I'm just going to reload that
  1814. 1:25:57page now let's check in the database in
  1815. 1:26:03the post views table what do we have
  1816. 1:26:05here so we have recorded
  1817. 1:26:07and this is the API IP address and this
  1818. 1:26:10is the IP of the docker container
  1819. 1:26:12running and we have the user agent we
  1820. 1:26:15have pulse ID user ID and dates of
  1821. 1:26:17course if I try to log out or try to
  1822. 1:26:20open the same article in incognito mode
  1823. 1:26:23it's going to make a second record but
  1824. 1:26:26right here we don't have user ID because
  1825. 1:26:28we made this nullable and just like this
  1826. 1:26:31we save like all the basic things we
  1827. 1:26:35need about the user who is basically
  1828. 1:26:37viewing the article and later we can
  1829. 1:26:40suggest to the user based on its views
  1830. 1:26:43which articles might be relevant for
  1831. 1:26:46that user all right here's one
  1832. 1:26:49additional uh thing which can be added
  1833. 1:26:51into this application and I give you
  1834. 1:26:53this as a challenge I'm not going to
  1835. 1:26:55implement this in this video
  1836. 1:26:57if I keep refreshing this page it's
  1837. 1:27:00gonna make records in the post Fields
  1838. 1:27:03table as many times you refresh all
  1839. 1:27:06right and as a suggestion you can
  1840. 1:27:09generate a random token and save this in
  1841. 1:27:12the user's cookie and you can give this
  1842. 1:27:14random token Associated a lifetime like
  1843. 1:27:17one hour for example and you will assume
  1844. 1:27:19that all views the specific user will
  1845. 1:27:23make on this article in one hour will be
  1846. 1:27:26considered as a single View and you are
  1847. 1:27:29not going to make records in the post
  1848. 1:27:31views table unless that one hour or
  1849. 1:27:34whatever time period you specify the
  1850. 1:27:37time period passes and that's good
  1851. 1:27:39because if the user opens the article
  1852. 1:27:41and for some reason decided to refresh
  1853. 1:27:44it or just close and reopened it
  1854. 1:27:46immediately so you're gonna make record
  1855. 1:27:49multiple times
  1856. 1:27:51okay you can assume that this is a
  1857. 1:27:53single View
  1858. 1:27:54but if the user checks that article like
  1859. 1:27:57few hours later or like uh tomorrow then
  1860. 1:28:01you can consider that this is a second
  1861. 1:28:02View
  1862. 1:28:03okay as I mentioned I'm not going to
  1863. 1:28:05implement this but as a challenge I
  1864. 1:28:07think it's really interesting and useful
  1865. 1:28:09so I give this challenge to you and let
  1866. 1:28:11me know in the comments section if any
  1867. 1:28:13one of you will implement this challenge
  1868. 1:28:15in this uh in this project all right I
  1869. 1:28:18would love to know about this
  1870. 1:28:21all right now we have that information
  1871. 1:28:23it's time to bring that in the admin
  1872. 1:28:26panel and display these probably above
  1873. 1:28:28the
  1874. 1:28:29um about this card to display number of
  1875. 1:28:32views for that specific post also number
  1876. 1:28:36of likes or the same as app folds and
  1877. 1:28:39downloads because we have all that
  1878. 1:28:41information in these like we just need
  1879. 1:28:43to Output them okay to display that kind
  1880. 1:28:45of information we need to create widgets
  1881. 1:28:48in filament so I'm going to open
  1882. 1:28:50filament PHP documentation and we can
  1883. 1:28:52search for uh widgets somewhere
  1884. 1:28:56let's search for widgets here we have
  1885. 1:28:59that
  1886. 1:29:00getting started okay so we need to
  1887. 1:29:02create a widget we can specify also the
  1888. 1:29:06resource and then we need to display
  1889. 1:29:11that widget in the post view so let's
  1890. 1:29:13start step by step so first I'm going to
  1891. 1:29:15create the widget I'm going to copy this
  1892. 1:29:17command and open uh PHP swarm I'm going
  1893. 1:29:21to close everything let's bring up the
  1894. 1:29:23terminal and execute uh phpr design make
  1895. 1:29:26filament widget let's call this post uh
  1896. 1:29:31post overview right
  1897. 1:29:33okay we can specify your resource but I
  1898. 1:29:37think we can leave this as it is right
  1899. 1:29:39now
  1900. 1:29:39uh
  1901. 1:29:42let's hit the enter okay post overview
  1902. 1:29:44was actually created let's open this
  1903. 1:29:46widget
  1904. 1:29:48post
  1905. 1:29:49overview
  1906. 1:29:51here we have it it also generated a
  1907. 1:29:54blade file for that so we can open also
  1908. 1:29:57post Dash overview which is the blade
  1909. 1:30:00file Associated to that specific widget
  1910. 1:30:03I'm going to type here hello from widget
  1911. 1:30:06okay we created the widget but we are
  1912. 1:30:09not using it yet let's go in the post
  1913. 1:30:13view app filament resources and we have
  1914. 1:30:18right here host resource inside there we
  1915. 1:30:21have a view post and that view post has
  1916. 1:30:25get a header get header widgets and
  1917. 1:30:29inside that get header widgets we can
  1918. 1:30:32check the appearing but it's returning
  1919. 1:30:34an empty array so we can return our
  1920. 1:30:37widget we should return our widget and
  1921. 1:30:40that's going to be post overview widget
  1922. 1:30:43class all right so now let's save this
  1923. 1:30:48and open the admin panel and just reload
  1924. 1:30:52the page and look at this so right here
  1925. 1:30:54we see hello from widget so we are using
  1926. 1:30:56already our widget
  1927. 1:30:59I want this widget to be on full width
  1928. 1:31:02by default it is
  1929. 1:31:04um like uh with a half half size but I
  1930. 1:31:07want this to be on full width and then
  1931. 1:31:09create three inner cards
  1932. 1:31:13um inside the actual blade so let me
  1933. 1:31:16actually do this in this widget post
  1934. 1:31:19overview
  1935. 1:31:20I'm going to Define uh called column
  1936. 1:31:24spun
  1937. 1:31:26column spot we actually we can actually
  1938. 1:31:28check what properties the parent class
  1939. 1:31:30the widget class has so we have a couple
  1940. 1:31:32of um a couple of properties right here
  1941. 1:31:34one of them is called span and I'm going
  1942. 1:31:36to specify the column
  1943. 1:31:38spawn to be actually three okay so let's
  1944. 1:31:42save these and reload and now we see
  1945. 1:31:44this to be on a full full width
  1946. 1:31:48and we need also some sort of a data
  1947. 1:31:51which needs to be passed to the Views to
  1948. 1:31:54check this impairment again so we see
  1949. 1:31:58this parent widget basically is a pure
  1950. 1:32:01Live Wire component as you can see it
  1951. 1:32:05extends for Livewire component so it has
  1952. 1:32:09somewhere render method it renders our
  1953. 1:32:12view past View and it passes get a view
  1954. 1:32:15data right so this get view data is
  1955. 1:32:19empty at the moment but we can
  1956. 1:32:22we can override that get a view data
  1957. 1:32:26function and return the data we need to
  1958. 1:32:30be passed to the Views so we need three
  1959. 1:32:34main things to be positive views like a
  1960. 1:32:37view count
  1961. 1:32:38number of views that specific post has
  1962. 1:32:42uh we are going to pass let's let me
  1963. 1:32:45leave empty right now we're going to
  1964. 1:32:47pass upvotes number of upvotes
  1965. 1:32:50and we're going to pass down volts
  1966. 1:32:54all right
  1967. 1:32:56let's start implementing from view uh
  1968. 1:32:59view count so from post view we are
  1969. 1:33:03gonna write aware
  1970. 1:33:05and when to specify post ID
  1971. 1:33:08equals
  1972. 1:33:11to some post ID and that post ID
  1973. 1:33:14basically can be taken from the record
  1974. 1:33:18of this widget because we are using this
  1975. 1:33:21widget inside view post
  1976. 1:33:24right here that view post is for one
  1977. 1:33:29specific post
  1978. 1:33:31and we can use record
  1979. 1:33:34we can use this record here so not sure
  1980. 1:33:38if this is declared right here record I
  1981. 1:33:41think this is not declared but it is
  1982. 1:33:43written in the documentation that we can
  1983. 1:33:45access that this record
  1984. 1:33:47This Record
  1985. 1:33:51and then obviously we can take the ID
  1986. 1:33:54I'm going to collapse the left side so
  1987. 1:33:56I'm going to take ID from here and then
  1988. 1:33:59let's execute count on that okay view
  1989. 1:34:02count
  1990. 1:34:03let's save this and check if this works
  1991. 1:34:06so far so view count variable needs to
  1992. 1:34:09be available in the post overview so
  1993. 1:34:12hello from widget and let's output view
  1994. 1:34:14count with dollar sign obviously so we
  1995. 1:34:17save this and reload the page
  1996. 1:34:20and let's have a look record uh
  1997. 1:34:23property record not found on component
  1998. 1:34:26let's check post overview all right this
  1999. 1:34:29is because we need to also Define this
  2000. 1:34:32record so that's going to be public
  2001. 1:34:35model record
  2002. 1:34:39to be null but we also need to specify
  2003. 1:34:41here question mark because uh because
  2004. 1:34:44this is now by default in the question
  2005. 1:34:46mark is necessary here let's actually
  2006. 1:34:48import the eloquent model
  2007. 1:34:51here we have that and whenever we Define
  2008. 1:34:54this now we should not have this error
  2009. 1:34:56anymore now look at this now we have
  2010. 1:34:58number of views on that specific post
  2011. 1:35:03that is perfect okay in the same way
  2012. 1:35:06let's do Up full downloads
  2013. 1:35:09avoid download where we specify
  2014. 1:35:13post ID
  2015. 1:35:15equals This Record ID
  2016. 1:35:20and we call also another we are
  2017. 1:35:24is upvote
  2018. 1:35:26equals one and finally we call count
  2019. 1:35:31like this and let's
  2020. 1:35:34let me grab this and simply we're going
  2021. 1:35:37to change
  2022. 1:35:38is upvote equals zero and let's change
  2023. 1:35:42this into integer or true or false we
  2024. 1:35:45can even use true or false or one or
  2025. 1:35:47zero as integers so I save this now
  2026. 1:35:50let's print those two variables as well
  2027. 1:35:53number of upfolds here
  2028. 1:35:56and number of down votes here so here we
  2029. 1:36:01go let's reload the page we see one up
  2030. 1:36:04vote and zero download if I go on post
  2031. 1:36:07and click on download button instead and
  2032. 1:36:10reload now we see Zero upvote and one
  2033. 1:36:13download okay now it's time to Simply
  2034. 1:36:16render this content nicely in this area
  2035. 1:36:22I'm going to open displayed file and
  2036. 1:36:25let's specify the main widget to have
  2037. 1:36:28the following CSS classes like let's
  2038. 1:36:31give it agreed and grid columns three
  2039. 1:36:35and let's give it also get three okay
  2040. 1:36:38inside there I'm gonna have three cards
  2041. 1:36:41so I'm going to duplicate this three
  2042. 1:36:44times and if I save this and have a look
  2043. 1:36:46we already see nice three cards right
  2044. 1:36:48with equal width and now let's define in
  2045. 1:36:53the first one we need to display view
  2046. 1:36:55count
  2047. 1:36:56uh let's use also like H2 to actually
  2048. 1:37:00Define what information we have this in
  2049. 1:37:02this card like views and let's give it
  2050. 1:37:04classes like text large
  2051. 1:37:08um above small let's give it text extra
  2052. 1:37:11large let's give it font bold let's give
  2053. 1:37:14it uh tracking light the following
  2054. 1:37:18classes and down below let's create one
  2055. 1:37:21div inside there let's give this div
  2056. 1:37:24Flex because I want to display icon as
  2057. 1:37:26well and give two in between and now
  2058. 1:37:29here we need the some kind of eye icon
  2059. 1:37:32and then we need view count
  2060. 1:37:36right so let's open now hero icons
  2061. 1:37:40and let's grab
  2062. 1:37:43I icon here
  2063. 1:37:46and let's paste right here save this and
  2064. 1:37:51have a look
  2065. 1:37:52okay views and this is 19 number of
  2066. 1:37:56views that's perfect now let's move on
  2067. 1:37:58the second one and we already have this
  2068. 1:38:01kind of template of the card so why
  2069. 1:38:04don't we delete the other cards and
  2070. 1:38:06simply duplicate this because we all
  2071. 1:38:08have all the CSS and right here we need
  2072. 1:38:11to display up folds we want to obviously
  2073. 1:38:14change this SVG so we can look for
  2074. 1:38:17thumbs up
  2075. 1:38:19called psvg
  2076. 1:38:21paste here
  2077. 1:38:24that is up folds by the way that should
  2078. 1:38:26be down volts the last one should be
  2079. 1:38:29down volts
  2080. 1:38:32and the other one should be upvotes and
  2081. 1:38:36my copied SVG will be for up folds and
  2082. 1:38:40let's also output the variable up folds
  2083. 1:38:43here this is downloads and now let's
  2084. 1:38:45copy SVG for downloads download votes
  2085. 1:38:48I'm gonna format the code oops
  2086. 1:38:51and here we have 1000 volts okay and
  2087. 1:38:54here's the overview now we have three
  2088. 1:38:56cards the first one displays views and
  2089. 1:38:59this is the the whole card let's
  2090. 1:39:02collapse this second displays up folds
  2091. 1:39:05and here we have the variable for
  2092. 1:39:06upvotes and the third one is for down
  2093. 1:39:09volts perfect so if I save this and now
  2094. 1:39:13reload admin panel we see views outputs
  2095. 1:39:16and down volts and let's just click on
  2096. 1:39:19thumbs up here and this one obviously
  2097. 1:39:22changes okay I think that's perfect now
  2098. 1:39:25let's make categories in posts
  2099. 1:39:27searchable in the admin panel because if
  2100. 1:39:30you have more posts it's going to be
  2101. 1:39:32hard to find your desired post so let's
  2102. 1:39:35open
  2103. 1:39:36well it's open let's close everything
  2104. 1:39:38and open
  2105. 1:39:41um oh it's called the list we need to
  2106. 1:39:44open
  2107. 1:39:45pulse resource and here we have tables
  2108. 1:39:49and forms information
  2109. 1:39:52so we don't care about the form at the
  2110. 1:39:55moment we care about the table and in
  2111. 1:39:57this table I'm going to specify that the
  2112. 1:40:00title is basically searchable field and
  2113. 1:40:03whenever you do this
  2114. 1:40:05in the admin panel you will see this
  2115. 1:40:07search box right here and then we can
  2116. 1:40:10search for JavaScript and here we go we
  2117. 1:40:13can search for lorem and we don't find
  2118. 1:40:15anything we can search for Alice
  2119. 1:40:20and here we find all Alice keywords
  2120. 1:40:24mentioned in the title and I think
  2121. 1:40:25that's perfect
  2122. 1:40:27now let's do the same thing on
  2123. 1:40:29categories I'm going to open
  2124. 1:40:32category resource
  2125. 1:40:34let's scroll down below on the title and
  2126. 1:40:37specify here searchable
  2127. 1:40:39[Music]
  2128. 1:40:41below the page and we see and we can
  2129. 1:40:42search for laravel here we find it
  2130. 1:40:47okay that's good it searches inside the
  2131. 1:40:50title for categories as well as for
  2132. 1:40:51posts however if you open posts and we
  2133. 1:40:54want to search some text inside body as
  2134. 1:40:58well let me edit this and in the body
  2135. 1:41:00right here I'm gonna add like a zura
  2136. 1:41:03keyword
  2137. 1:41:04okay so if I save this and go in the
  2138. 1:41:06post and then try to search zura I
  2139. 1:41:08couldn't find that because this search
  2140. 1:41:10is only inside title right if I specify
  2141. 1:41:13zura in title obviously it's going to
  2142. 1:41:15find but this is not what we want we
  2143. 1:41:17want to search in the body as well we
  2144. 1:41:20can specify to this searchable method
  2145. 1:41:22array of attributes it needs to search
  2146. 1:41:26in
  2147. 1:41:28in this case we will specify title in
  2148. 1:41:30body
  2149. 1:41:31in this post resource so I save this and
  2150. 1:41:34now if I type 0 right here it's going to
  2151. 1:41:37find this because it searches now inside
  2152. 1:41:39body as well
  2153. 1:41:40I think that's awesome
  2154. 1:41:42the searchable even has if we just click
  2155. 1:41:45on this it has a couple of options right
  2156. 1:41:47here you can even specify whether the
  2157. 1:41:50search is for individual column or This
  2158. 1:41:54Global search like if you specify here
  2159. 1:41:56that this is for is
  2160. 1:41:59is individual uh actually let me let me
  2161. 1:42:03do like this is individual and we
  2162. 1:42:06specify true here
  2163. 1:42:08this means the following we are gonna
  2164. 1:42:11see this individual search field in that
  2165. 1:42:15specific column
  2166. 1:42:17and we can obviously add additional
  2167. 1:42:19searchable columns right here like a
  2168. 1:42:22filter by status whether it's an active
  2169. 1:42:25or not we can filter by publish date and
  2170. 1:42:29so on
  2171. 1:42:31okay in this case I'd rather to have a
  2172. 1:42:33single search because I don't have that
  2173. 1:42:35much cons right there so I'm going to
  2174. 1:42:38specify searchable with the title in
  2175. 1:42:40body and I can also specify sortable if
  2176. 1:42:44I want so
  2177. 1:42:45so if I just follow the page I see that
  2178. 1:42:47the title is now sortable and then click
  2179. 1:42:49on this and sort uh by the actual title
  2180. 1:42:52and the sortable is I think very useful
  2181. 1:42:55so we can specify this on publish that
  2182. 1:42:58as well and maybe on active as well
  2183. 1:43:02so if I save and reload we see that we
  2184. 1:43:04can sort burst only deactivated
  2185. 1:43:08posts and then actives one and if we
  2186. 1:43:10click on the publish date we can do
  2187. 1:43:12something similar right here
  2188. 1:43:16I'm going to add this sortable to
  2189. 1:43:18category Resource as well on title and
  2190. 1:43:23probably on updated it as well
  2191. 1:43:26now I'm going to add one useful thing to
  2192. 1:43:28every post whether you're in a post
  2193. 1:43:31inner page or in list as well and that's
  2194. 1:43:34going to be estimated read time in a
  2195. 1:43:37human readable format and also number of
  2196. 1:43:40words for that article so that when
  2197. 1:43:43you're looking through the blog website
  2198. 1:43:44you immediately know if this is not too
  2199. 1:43:48long probably you want to click it and
  2200. 1:43:50just read it okay if it's like five
  2201. 1:43:51minute two minutes article so I think
  2202. 1:43:54that's that's really handy and useful
  2203. 1:43:57feature so let's actually uh open uh
  2204. 1:44:00post model I'm going to do this in post
  2205. 1:44:02model and I'm going to create a custom
  2206. 1:44:04attribute where's the post model here I
  2207. 1:44:08have it
  2208. 1:44:09okay let's close to the left side and
  2209. 1:44:12maybe at the very bottom I'm going to
  2210. 1:44:14create a public function human read time
  2211. 1:44:20and that's going to return custom
  2212. 1:44:23attribute from illuminate database
  2213. 1:44:25eloquent class attributes so we'll
  2214. 1:44:28return new attribute
  2215. 1:44:33and we are going to Define only getter
  2216. 1:44:36for this
  2217. 1:44:38we get value and actual attribute here
  2218. 1:44:43and now what do we need to return from
  2219. 1:44:46here so we're going to return number of
  2220. 1:44:48minutes to read that article that post
  2221. 1:44:52as well as a number of words so let's
  2222. 1:44:56start by counting number of words and
  2223. 1:44:59that will be using Str facade
  2224. 1:45:02uh
  2225. 1:45:04okay so it's your helper we're going to
  2226. 1:45:06execute words method here and
  2227. 1:45:10actually we need to specify a word count
  2228. 1:45:13and let's specify
  2229. 1:45:15the body and it's going to be
  2230. 1:45:18from attributes let's call this
  2231. 1:45:21attributes in plural form from
  2232. 1:45:24attributes to get the body but that body
  2233. 1:45:28will contain HTML tags as well so let's
  2234. 1:45:31run strip tags endbody
  2235. 1:45:35okay so we have number of words
  2236. 1:45:39how to define a reading minutes for that
  2237. 1:45:42specific
  2238. 1:45:43words like to take an estimate average
  2239. 1:45:48number of words per minute it is about
  2240. 1:45:52like a 200 words so we call sale method
  2241. 1:45:59divide number of words on 200 and just
  2242. 1:46:04like this we have minutes
  2243. 1:46:07and then we're going to return from here
  2244. 1:46:09minutes but we are going to also specify
  2245. 1:46:13like a mean right here as a string but
  2246. 1:46:18based on whether this means is a one or
  2247. 1:46:21two we either need mean or means or like
  2248. 1:46:25minutes whatever we decide so in this
  2249. 1:46:27case I'm going to wrap the word mean and
  2250. 1:46:33then specify that I want this to be
  2251. 1:46:35converted into plural based on mints
  2252. 1:46:39values and just like this we have number
  2253. 1:46:43of means I'm going to leave a number of
  2254. 1:46:45words
  2255. 1:46:46unimplemented at the moment and let's
  2256. 1:46:49open post item blade and probably here
  2257. 1:46:54next to the get formatted date we are
  2258. 1:46:57going to Output post and whatever is the
  2259. 1:47:01name like human read time in a camel
  2260. 1:47:04case we need to convert this into
  2261. 1:47:05underscore format human 1 read time so I
  2262. 1:47:10save this and reload the page and we see
  2263. 1:47:13five means here five minutes here all of
  2264. 1:47:16them probably will be five minutes
  2265. 1:47:17except the first one this is just one
  2266. 1:47:19mint right so that's excellent now let's
  2267. 1:47:23go in the post and append right here
  2268. 1:47:26number of words as well like comma
  2269. 1:47:29and then
  2270. 1:47:31words
  2271. 1:47:32space
  2272. 1:47:35let's wrap
  2273. 1:47:38oops
  2274. 1:47:40words in called plural on that
  2275. 1:47:44on words
  2276. 1:47:46here we go we format everything and
  2277. 1:47:49reload the page and we see one minute 90
  2278. 1:47:51words like five minutes nine hundred
  2279. 1:47:54something words okay and we'll see five
  2280. 1:47:57minutes and on the others basically will
  2281. 1:47:59have roughly the same number of words
  2282. 1:48:01but if we edit the article which is
  2283. 1:48:05created by us and simply copy let's
  2284. 1:48:08remove the Zero by the way and copy and
  2285. 1:48:11paste these multiple times and click
  2286. 1:48:13save changes reload the page at the very
  2287. 1:48:16top we see three minutes 200 450 words
  2288. 1:48:19so this is it and we can output this
  2289. 1:48:22information on the inner page as well so
  2290. 1:48:24I'm going to open view dot blade
  2291. 1:48:29PHP this one and scroll down below and
  2292. 1:48:34right here we output
  2293. 1:48:37post human read time
  2294. 1:48:41so we save reload
  2295. 1:48:45and here we see that
  2296. 1:48:47perfect
  2297. 1:48:49now I'm going to start working on home
  2298. 1:48:51page and I'm going to define a couple of
  2299. 1:48:54sections on the home page just modify
  2300. 1:48:56that
  2301. 1:48:57to make it more like a home page design
  2302. 1:49:00where we're going to have an overview of
  2303. 1:49:03our blog blog website like I'm going to
  2304. 1:49:06display what is the latest post I'm
  2305. 1:49:08going to show the most popular three
  2306. 1:49:10articles actually let's open post
  2307. 1:49:14controller or maybe we can start from
  2308. 1:49:16web PHP and have a look so we have this
  2309. 1:49:19post controller index method which is
  2310. 1:49:22actually rendering the home so I think
  2311. 1:49:24we should rename this method to home
  2312. 1:49:26from here and here as well and at the
  2313. 1:49:29moment we are just rendering
  2314. 1:49:3110 posts through the pagination so I'm
  2315. 1:49:36going to completely remove this
  2316. 1:49:39and I'm going to Define which is the
  2317. 1:49:41latest post so we want to show latest
  2318. 1:49:43post I'm going to show the most popular
  2319. 1:49:48uh three posts based on upvotes I'm
  2320. 1:49:53going to show recommended
  2321. 1:49:57posts based on user user app folds if
  2322. 1:50:03the user is authorized okay so if
  2323. 1:50:06authorized however if the user is not
  2324. 1:50:08authorized
  2325. 1:50:11um let's not authorized let's define
  2326. 1:50:16um
  2327. 1:50:17popular
  2328. 1:50:19posts based on views
  2329. 1:50:24so and let's fix the typo
  2330. 1:50:28and we are gonna also show top
  2331. 1:50:31categories
  2332. 1:50:34or maybe like a recent
  2333. 1:50:37recent
  2334. 1:50:38categories with their latest
  2335. 1:50:44posts okay so I want to have these four
  2336. 1:50:48main sections
  2337. 1:50:50um on my on my website
  2338. 1:50:54and let's open
  2339. 1:50:55a home blade PHP and we are going to
  2340. 1:51:00remove sidebar and everything and I'm
  2341. 1:51:02going to define those
  2342. 1:51:04um four four sections in the following
  2343. 1:51:07way so we have this container and inside
  2344. 1:51:09there I'm going to Define one div and
  2345. 1:51:12that's going to be the header section
  2346. 1:51:14inside that div I will have
  2347. 1:51:17latest post section and I'm gonna have
  2348. 1:51:23um
  2349. 1:51:25popular
  2350. 1:51:26posts popular
  2351. 1:51:28three posts okay so that's going to be
  2352. 1:51:32the second div and this will have let's
  2353. 1:51:35give it proper CSS classes this will
  2354. 1:51:37have a grid let's give it grid calls one
  2355. 1:51:41but above medium screen
  2356. 1:51:43let's give it greed calls three maybe
  2357. 1:51:49let's give it also Gib four
  2358. 1:51:52okay we should put this
  2359. 1:51:55in a comment
  2360. 1:51:58like this uh
  2361. 1:52:02hold on okay like this
  2362. 1:52:06we need
  2363. 1:52:09comment here as well
  2364. 1:52:12popular three posts okay and at the very
  2365. 1:52:16bottom I'm gonna have two more div
  2366. 1:52:17elements
  2367. 1:52:19and this one will be recommended
  2368. 1:52:25posts
  2369. 1:52:30and this one will be latest articles
  2370. 1:52:34um sorry latest categories
  2371. 1:52:40like this
  2372. 1:52:42okay perfect now we need to feel those
  2373. 1:52:45gaps if I just type dummy text latest
  2374. 1:52:48post here maybe we can Define also
  2375. 1:52:51heading of that section like H2 let's
  2376. 1:52:54give it proper CSS classes like I'm
  2377. 1:52:57going to give it a text large and above
  2378. 1:52:59small let's give it text a text EXO
  2379. 1:53:02let's also give it a font bold and give
  2380. 1:53:07it text blue 500 give it uppercase
  2381. 1:53:11everything
  2382. 1:53:12let's give it also padding button one
  2383. 1:53:15and Border a bottom two I'm going to
  2384. 1:53:18give it also border blue
  2385. 1:53:21um Order Blue 500 okay and maybe small
  2386. 1:53:25margin as well
  2387. 1:53:27and inside there I'm going to type
  2388. 1:53:29latest
  2389. 1:53:30post now if I save this and have a look
  2390. 1:53:33we have a nerve and the compact we don't
  2391. 1:53:37pass anything so let's remove compact
  2392. 1:53:40completely I say this reload the page
  2393. 1:53:43and we see this latest post now that's
  2394. 1:53:47good however this latest post I want to
  2395. 1:53:49give it a call span 2. I want this to
  2396. 1:53:53take the two third of the entire screen
  2397. 1:53:57and then this one will have one third
  2398. 1:54:01okay
  2399. 1:54:02um
  2400. 1:54:03I think this is good
  2401. 1:54:05create grid calls one above
  2402. 1:54:11why doesn't this take the
  2403. 1:54:13to Third
  2404. 1:54:17because this doesn't have full width
  2405. 1:54:20and I guess this is the reason
  2406. 1:54:24uh this one has Flex aha so we we need
  2407. 1:54:27to remove this Flex it shouldn't be Flex
  2408. 1:54:30okay so now this takes two thirds I
  2409. 1:54:32think the container with for the home
  2410. 1:54:34page is a little bit too large so I'm
  2411. 1:54:36going to reduce it Max with maybe like a
  2412. 1:54:393XL let's see how it goes
  2413. 1:54:43um okay let's let's try let's start with
  2414. 1:54:45this and have a look
  2415. 1:54:47okay now we have this latest post I can
  2416. 1:54:49copy this title and that will be popular
  2417. 1:54:53posts
  2418. 1:54:55uh here we will have
  2419. 1:54:58recommended
  2420. 1:55:01recommended posts and down below we have
  2421. 1:55:04latest categories
  2422. 1:55:08uh recent
  2423. 1:55:10recent categories maybe or recent posts
  2424. 1:55:14okay let's give it recent categories
  2425. 1:55:18okay so we save this and we have uh four
  2426. 1:55:22four sections as we as we defined now we
  2427. 1:55:25need to pass proper variables to fill
  2428. 1:55:28those sections right so now we need to
  2429. 1:55:30work inside the post controller and
  2430. 1:55:33let's start with the latest post which
  2431. 1:55:35is slightly easier compared to others
  2432. 1:55:38from post we are gonna uh query where
  2433. 1:55:42active
  2434. 1:55:44so first flag needs it needs to be
  2435. 1:55:47active specify one as an integer we need
  2436. 1:55:51to also Define uh where date
  2437. 1:55:55published
  2438. 1:55:58eight needs to be
  2439. 1:56:01um
  2440. 1:56:02less than
  2441. 1:56:04carbon now
  2442. 1:56:07okay so it needs to be published by date
  2443. 1:56:09and Status means to be active as well so
  2444. 1:56:12let's order by
  2445. 1:56:14order by published
  2446. 1:56:17it descending
  2447. 1:56:21and I want to get limit one
  2448. 1:56:25and then first
  2449. 1:56:29okay I think I have everything correctly
  2450. 1:56:31so this latest post now can be passed to
  2451. 1:56:35view
  2452. 1:56:37like this so now let's print if we have
  2453. 1:56:40latest post here
  2454. 1:56:43latest post
  2455. 1:56:46save that
  2456. 1:56:47and I do have this here and I'm going to
  2457. 1:56:50actually use existing
  2458. 1:56:52component X post item component and
  2459. 1:56:56specify here post to be latest post
  2460. 1:57:01okay
  2461. 1:57:03save this and here is the latest post
  2462. 1:57:06information on the home page awesome now
  2463. 1:57:10let's move on the popular posts
  2464. 1:57:12so how should we Define the popularity
  2465. 1:57:16of the post we need to do this based on
  2466. 1:57:19number of upfolds so let me create a
  2467. 1:57:22variable first popular posts equals post
  2468. 1:57:26uh let's run query
  2469. 1:57:30let's join these we need to join this
  2470. 1:57:33into upvote downloads table up vote down
  2471. 1:57:37volts
  2472. 1:57:39where posts ID
  2473. 1:57:42equals to upvote
  2474. 1:57:45down votes
  2475. 1:57:47dot post underscore ID
  2476. 1:57:51okay so we join this now we need to
  2477. 1:57:54select
  2478. 1:57:56we select uh we're doing it so we need
  2479. 1:57:59posts everything from Posts
  2480. 1:58:02let's also select number of upfolds for
  2481. 1:58:08that post because then we need to order
  2482. 1:58:11by number of upvotes and if we don't
  2483. 1:58:14select put this in the select we won't
  2484. 1:58:17be able to order by by that so in this
  2485. 1:58:21case I'm going to use DB roll and
  2486. 1:58:24specify here
  2487. 1:58:25account
  2488. 1:58:29upvote down votes ID and let's give it
  2489. 1:58:32an alias is
  2490. 1:58:34upfold count right so we need to add
  2491. 1:58:40additional wear here
  2492. 1:58:41we just don't want to query every
  2493. 1:58:44everything from upvote downloads because
  2494. 1:58:46there's a flag is upvote needs to be
  2495. 1:58:50equal one we don't want those up for
  2496. 1:58:54download records which has download
  2497. 1:58:56right
  2498. 1:58:59so in the weird I'm going to specify a
  2499. 1:59:01function which will be query
  2500. 1:59:07and on that query I'm going to run where
  2501. 1:59:12upvote down volts
  2502. 1:59:15is
  2503. 1:59:17upvote
  2504. 1:59:19equals
  2505. 1:59:21one
  2506. 1:59:22okay
  2507. 1:59:24okay perfect let's add additional wear
  2508. 1:59:28so we want those posts we basically need
  2509. 1:59:32to grab this no this part because we
  2510. 1:59:37want to get only those posts which has
  2511. 1:59:40active one and published it is in the
  2512. 1:59:43past
  2513. 1:59:44and we want to order by this
  2514. 1:59:48order by descending by the following the
  2515. 1:59:53following name like a count of upvote
  2516. 1:59:56down votes right so we specify upvote
  2517. 1:59:59download here we also need to run Group
  2518. 2:00:02by posts ID we don't want duplicate the
  2519. 2:00:06records that's why we need to run Group
  2520. 2:00:08by and finally we need to limit this to
  2521. 2:00:11get three records and let's call get
  2522. 2:00:14okay if I don't make any mistake we
  2523. 2:00:17should have popular posts by their
  2524. 2:00:19number of upfolds
  2525. 2:00:22okay let's pass this popular posts right
  2526. 2:00:25here
  2527. 2:00:26let's go in the home blade and we have
  2528. 2:00:29popular posts here and let's output that
  2529. 2:00:32let's have a look okay we don't have any
  2530. 2:00:35error it probably means that we have
  2531. 2:00:37successfully implemented that so now we
  2532. 2:00:40need to iterate over our popular posts
  2533. 2:00:43for each popular posts is post
  2534. 2:00:48let's create a div let's give this Steve
  2535. 2:00:51greed greed
  2536. 2:00:54calls
  2537. 2:00:56uh maybe four let's give it skip two
  2538. 2:00:59inside there I'm going to create one div
  2539. 2:01:01which is going to be the image wrapper
  2540. 2:01:03so in the source we're going to specify
  2541. 2:01:06post get thumbnail
  2542. 2:01:13let's specify alt to be post
  2543. 2:01:16title
  2544. 2:01:18like this and let's specify second div
  2545. 2:01:22inside there we're going to have maybe
  2546. 2:01:24inside H3 post title
  2547. 2:01:28and we need like a short description
  2548. 2:01:31like we have it in the post item so we
  2549. 2:01:34need to use the same method short body
  2550. 2:01:37short body here we have this method okay
  2551. 2:01:41let's
  2552. 2:01:44let's print it
  2553. 2:01:46post
  2554. 2:01:48uh short body
  2555. 2:01:50I have feeling that this short body will
  2556. 2:01:53be too large for that section
  2557. 2:01:56let's have a look
  2558. 2:01:57the second div should have called span
  2559. 2:02:02of three so basically we are splitting
  2560. 2:02:04the entire width on four equal spaces
  2561. 2:02:07then this image will have one part in
  2562. 2:02:09the description and title and the short
  2563. 2:02:11body will have three part so if I save
  2564. 2:02:14everything it should be like this okay
  2565. 2:02:17an image and the title in the body this
  2566. 2:02:20body needs to have smaller fonts so
  2567. 2:02:23let's specify text SM
  2568. 2:02:26okay that's good uh let's give it also
  2569. 2:02:29text
  2570. 2:02:31semi-bold
  2571. 2:02:34okay I think that's good but again as I
  2572. 2:02:38mentioned this description is too large
  2573. 2:02:39so inside short body I'm gonna specify
  2574. 2:02:43I'm gonna Define uh like Words variable
  2575. 2:02:47which by default will be 30. so that's
  2576. 2:02:49that's a good lesson to learn so I'm
  2577. 2:02:52using this short body from somewhere
  2578. 2:02:53else I want to modify this short body
  2579. 2:02:56arguments so that it doesn't break other
  2580. 2:02:59place
  2581. 2:03:00if I just make this argument required
  2582. 2:03:04like words here and then I specify words
  2583. 2:03:07here it's going to break the other
  2584. 2:03:09places because other places where I use
  2585. 2:03:10this short body we don't pass these
  2586. 2:03:13words variable so we need to make these
  2587. 2:03:16words optional so that by default it
  2588. 2:03:19still is 30 and from other places if we
  2589. 2:03:22are using this short body we don't pass
  2590. 2:03:24this 30 and we don't have any problems
  2591. 2:03:27but in this case on home page I want to
  2592. 2:03:30pass 10 instead of 30 10 words so now
  2593. 2:03:35this is more liked
  2594. 2:03:38okay that's perfect however on this
  2595. 2:03:41container I'm going to give it like a
  2596. 2:03:43slight padding top adding top Maybe two
  2597. 2:03:49so this image is moved down and that's
  2598. 2:03:52it you have it
  2599. 2:03:55however
  2600. 2:03:56why we don't see more than one post here
  2601. 2:04:05okay don't we have other posts let's
  2602. 2:04:09check the post controller
  2603. 2:04:12so we joined this I put downwards
  2604. 2:04:18okay I see the reason so because we
  2605. 2:04:21write the left join here
  2606. 2:04:23it basically means that
  2607. 2:04:26upfo download might not even exist
  2608. 2:04:29um on the post
  2609. 2:04:31and in this case we in the we are close
  2610. 2:04:33we have this now is upvote needs to be
  2611. 2:04:37equal always one and that's basically
  2612. 2:04:39what causes the problem so here we can
  2613. 2:04:42specify
  2614. 2:04:43we are
  2615. 2:04:45we are null to be more specific so
  2616. 2:04:49upvote download
  2617. 2:04:51specify up vote down volts
  2618. 2:04:56is up fold needs to be either null
  2619. 2:05:00or its value needs to be one it will be
  2620. 2:05:03now whenever the left join doesn't
  2621. 2:05:06return any any anything basically so
  2622. 2:05:08whenever the post doesn't have upload
  2623. 2:05:10downwards this will be null however if
  2624. 2:05:13there exists a record for the
  2625. 2:05:16corresponding post inside app vote
  2626. 2:05:18downloads table
  2627. 2:05:20this will return record and then the
  2628. 2:05:22value needs to be won so if I save this
  2629. 2:05:24now and reload the page
  2630. 2:05:29they break anything
  2631. 2:05:34okay we don't see anything
  2632. 2:05:39oops here we need or where
  2633. 2:05:42the upflow down which needs to be now or
  2634. 2:05:45it needs to be one so I think that it is
  2635. 2:05:49here we go so now we have
  2636. 2:05:51three articles right here because we
  2637. 2:05:55basically are limiting to three so we
  2638. 2:05:57have three articles image title let's
  2639. 2:06:00make title
  2640. 2:06:01a little bit
  2641. 2:06:03like a maybe bold
  2642. 2:06:06to stand out from from anything else
  2643. 2:06:10um
  2644. 2:06:12okay let's give it
  2645. 2:06:14uppercase Maybe
  2646. 2:06:18no I don't like text bold white Expo
  2647. 2:06:23doesn't work
  2648. 2:06:24as I expected
  2649. 2:06:29is their text extra small
  2650. 2:06:32on buddy okay if we reduce the body we
  2651. 2:06:35can reduce this one as well so we give
  2652. 2:06:37it a text small uppercase Maybe
  2653. 2:06:41okay not paid
  2654. 2:06:43and we can give this one also no wrap
  2655. 2:06:47text no wrap or white space no wrap
  2656. 2:06:51um
  2657. 2:06:53okay I'm gonna look for this talwind CSS
  2658. 2:06:57a white space no wrap
  2659. 2:07:03okay I think this is the class so let's
  2660. 2:07:06specify this here
  2661. 2:07:10it goes on full width and
  2662. 2:07:16let's search for also Talon CSS text
  2663. 2:07:21overflow
  2664. 2:07:23ellipsis
  2665. 2:07:27okay I want to show simply three dots
  2666. 2:07:30there
  2667. 2:07:31truncate does that class
  2668. 2:07:34do what we want let's see
  2669. 2:07:37okay yeah this does what we want
  2670. 2:07:40I'm gonna add extra margin margin bottom
  2671. 2:07:43three between each posts
  2672. 2:07:48like these maybe even
  2673. 2:07:50four
  2674. 2:07:53okay so the latest post and the latest
  2675. 2:07:56popular post like a three post
  2676. 2:07:59well I think that
  2677. 2:08:01um
  2678. 2:08:02the
  2679. 2:08:04the text size is too small compared to
  2680. 2:08:08the left one so we should probably even
  2681. 2:08:10reduce the left side but in this case we
  2682. 2:08:13are using the uh same uh host item
  2683. 2:08:17component what we have on the other
  2684. 2:08:19pages so changing this will affect the
  2685. 2:08:22other Pages as well so I don't want to
  2686. 2:08:23spend too much time on design part again
  2687. 2:08:26like we can simply increase the number
  2688. 2:08:29of items into five here
  2689. 2:08:33um reload the page and again if we add
  2690. 2:08:35extra extra things like
  2691. 2:08:40well let me show you like we have this
  2692. 2:08:44by who who is the owner of this article
  2693. 2:08:48basically or what's the read time of
  2694. 2:08:51this article or what are the categories
  2695. 2:08:54so let's grab the categories section in
  2696. 2:08:57the home page and let's put this below
  2697. 2:09:01title here maybe
  2698. 2:09:04so I save this here we see now
  2699. 2:09:06JavaScript is a category we can slightly
  2700. 2:09:10change instead of text blue 700 let's
  2701. 2:09:14give it PG blue 700 and give it text
  2702. 2:09:18white and padding padding two
  2703. 2:09:22something like this
  2704. 2:09:25padding one and rounded and instead of
  2705. 2:09:31700 let's give it 500.
  2706. 2:09:34okay so we create this small small tags
  2707. 2:09:37let's give it text excess extra small
  2708. 2:09:45okay so those are the tags
  2709. 2:09:47for that specific
  2710. 2:09:51of that specific article
  2711. 2:09:56and that section needs to have like a
  2712. 2:10:00margin button as well
  2713. 2:10:04okay
  2714. 2:10:06we can this div is rendered now for
  2715. 2:10:09every
  2716. 2:10:10for every article
  2717. 2:10:12even though there are no categories
  2718. 2:10:15because we don't have this in the if
  2719. 2:10:16statement we can actually wrap this
  2720. 2:10:19if the post categories is not empty then
  2721. 2:10:23render this part which I'm not going to
  2722. 2:10:25do you can do it if you want
  2723. 2:10:29I'm going to reduce this part adding tab
  2724. 2:10:32on the image so the image needs to be
  2725. 2:10:34moved a little bit up
  2726. 2:10:37and I can finally
  2727. 2:10:39give a slight increase on the container
  2728. 2:10:42width okay so this is it
  2729. 2:10:45we have the latest post
  2730. 2:10:47we have the popular posts we can
  2731. 2:10:50increase the
  2732. 2:10:52Gap right here up to eight Maybe
  2733. 2:10:58that's that's good that's good and of
  2734. 2:11:01course whenever we click on one of the
  2735. 2:11:02posts when it needs to open the inner
  2736. 2:11:04page so if we go in the popular post
  2737. 2:11:07section
  2738. 2:11:08uh here maybe on the image if I change
  2739. 2:11:12this into a and if I change this
  2740. 2:11:16if I wrap this
  2741. 2:11:19into a as well
  2742. 2:11:21and give this one href roads
  2743. 2:11:27um I'm going to check in the rotor here
  2744. 2:11:30we have this View and I need to pass
  2745. 2:11:32post so View and post
  2746. 2:11:36and do the same thing
  2747. 2:11:40here
  2748. 2:11:41so I need
  2749. 2:11:43you and post I save and reload the page
  2750. 2:11:47and I see when I click on this it opens
  2751. 2:11:49the article click on this it opens the
  2752. 2:11:51article it also keeps track which
  2753. 2:11:53articles I opened
  2754. 2:11:56not too bad not too bad let's put extra
  2755. 2:12:00button like we have on the post item
  2756. 2:12:03continue reading button
  2757. 2:12:06and by the way it's the the continue
  2758. 2:12:07reading button doesn't have proper link
  2759. 2:12:10here which we can specify
  2760. 2:12:14like oops
  2761. 2:12:16like
  2762. 2:12:18we did
  2763. 2:12:19here I'm going to take this href
  2764. 2:12:22specify here
  2765. 2:12:26now if I click this continue reading it
  2766. 2:12:29opens the inner page and I'm going to
  2767. 2:12:32get this continue reading and put this
  2768. 2:12:35here
  2769. 2:12:39okay the text size needs to be
  2770. 2:12:44text
  2771. 2:12:46s
  2772. 2:12:48extra small
  2773. 2:12:50and the arrow
  2774. 2:12:54yeah here here it uses font awesome
  2775. 2:12:57Arrow which is fine
  2776. 2:13:01okay now we are more like uh filling all
  2777. 2:13:05the missing vertical hate compared to
  2778. 2:13:08the left latest Post article which is
  2779. 2:13:12fine
  2780. 2:13:12okay and we have these links also and
  2781. 2:13:16clicking on the image everything is
  2782. 2:13:17working fine okay so we have this now
  2783. 2:13:19two sections of home page active and
  2784. 2:13:21ready let's move on to the next one
  2785. 2:13:23which is recommended posts
  2786. 2:13:26I'm going to open post controller and
  2787. 2:13:28let's now Define the I think this is
  2788. 2:13:31very interesting part
  2789. 2:13:33so first let's get the authorized user
  2790. 2:13:35information I'm going to get this from
  2791. 2:13:37auth user then I'm going to write an if
  2792. 2:13:41statement if the user exists it means
  2793. 2:13:44that we're going to write a different
  2794. 2:13:45query if the user doesn't exist we are
  2795. 2:13:48going to write different query the else
  2796. 2:13:50part is slightly easier so I'm going to
  2797. 2:13:54actually do this and it's very similar
  2798. 2:13:56to popular posts so I'm going to get
  2799. 2:13:59this however I'm going to modify a few
  2800. 2:14:01things
  2801. 2:14:03let's give it also name different name
  2802. 2:14:05recommended
  2803. 2:14:07posts so we start query from Posts we
  2804. 2:14:11left join on poster views
  2805. 2:14:15post ID equals to post views post ID
  2806. 2:14:18then we select posts and post views ID
  2807. 2:14:23is view count let's call this view count
  2808. 2:14:29then we write additional wear
  2809. 2:14:31uh this wheel basically is not necessary
  2810. 2:14:34because
  2811. 2:14:35if there is a record in the post views
  2812. 2:14:37table
  2813. 2:14:38it's just it just needs to be counted
  2814. 2:14:40okay we don't care about anything else
  2815. 2:14:42so I can remove this
  2816. 2:14:44we are activities to be won and
  2817. 2:14:46published it needs to be in the past
  2818. 2:14:47that's totally necessary and then we
  2819. 2:14:50have order by descending in this case
  2820. 2:14:52order by view count
  2821. 2:14:54then we have group by post ID and limit
  2822. 2:14:585 and get so we have this recommended
  2823. 2:15:00post we can already pass that that's for
  2824. 2:15:04non-authorized users
  2825. 2:15:06now let's define it for authorized users
  2826. 2:15:09which is slightly more challenging in my
  2827. 2:15:12opinion
  2828. 2:15:14so first I'm going to define the main
  2829. 2:15:16query and I'm going to Define sub query
  2830. 2:15:18as well on which I want to make a join
  2831. 2:15:22so the idea is the following I want
  2832. 2:15:26to query posts which are in the same
  2833. 2:15:30category
  2834. 2:15:32on which in which I already upvoted some
  2835. 2:15:36of the posts so if I uploaded for
  2836. 2:15:38example a post from the JavaScript
  2837. 2:15:41category in my recommended post I will
  2838. 2:15:44see another post from the JavaScript
  2839. 2:15:46category okay this is what I'm going to
  2840. 2:15:49do
  2841. 2:15:50so let's start
  2842. 2:15:52defining recommended posts equals posts
  2843. 2:15:57query
  2844. 2:15:59we need a left join on
  2845. 2:16:01left joint on category post
  2846. 2:16:06let's give it to nalius as well like is
  2847. 2:16:08in category
  2848. 2:16:10both SIDS CP Maybe
  2849. 2:16:12we are posts ID
  2850. 2:16:14equals to CP
  2851. 2:16:18post ID
  2852. 2:16:22okay I'm gonna write another lift join
  2853. 2:16:25but in this case I want a sub-qa
  2854. 2:16:28and that sub query um let's let's call
  2855. 2:16:31this um like left join
  2856. 2:16:34there's going to be some sort of string
  2857. 2:16:36I'm going to use that left join at the
  2858. 2:16:39moment
  2859. 2:16:41I'm going to also Define extraware
  2860. 2:16:44clause here
  2861. 2:16:46well I think we should first Define what
  2862. 2:16:49should be this left join so that's going
  2863. 2:16:52to be select
  2864. 2:16:54from
  2865. 2:16:56upvote down volts
  2866. 2:16:59down volts
  2867. 2:17:01we're going to join into category post
  2868. 2:17:06as CPU on upfold downloads
  2869. 2:17:12host ID
  2870. 2:17:14equals CP let's move this down
  2871. 2:17:18as CP
  2872. 2:17:20host ID so we are selecting from upload
  2873. 2:17:24downloads then join to category post and
  2874. 2:17:27finally we're going to query we need
  2875. 2:17:30extra wear closes here but finally we're
  2876. 2:17:32going to query category ID from this
  2877. 2:17:35category post category ID and we need a
  2878. 2:17:40post ID
  2879. 2:17:42and let's give extra weird we are upvote
  2880. 2:17:48down votes
  2881. 2:17:51is upvote obviously
  2882. 2:17:54is
  2883. 2:17:55upfold equals one
  2884. 2:17:58and and the main thing is that we need
  2885. 2:18:02to get this for the currently authorized
  2886. 2:18:03user so and
  2887. 2:18:06upvote downloads
  2888. 2:18:09user ID
  2889. 2:18:12equals to something
  2890. 2:18:14so again let's have a look let's get
  2891. 2:18:18this
  2892. 2:18:19um
  2893. 2:18:20get the full idea of this select so
  2894. 2:18:23we're not query from our full downloads
  2895. 2:18:25We are the current user has upvoted this
  2896. 2:18:29where Clause means that
  2897. 2:18:31and finally it's very simple and finally
  2898. 2:18:33we're going to get the category ID and
  2899. 2:18:35post ID
  2900. 2:18:36okay
  2901. 2:18:39so let's wrap this in parenthesis
  2902. 2:18:43and let's give it a like an alias as T
  2903. 2:18:46because we're going to write a join here
  2904. 2:18:48on that and I'm going to give him give
  2905. 2:18:51it an alias like a t
  2906. 2:18:53so now we are left joining on the
  2907. 2:18:55following query
  2908. 2:18:56I'm going to specify here
  2909. 2:18:59this join
  2910. 2:19:01then
  2911. 2:19:02on join
  2912. 2:19:04I'm going to call
  2913. 2:19:05T category ID
  2914. 2:19:10equals to
  2915. 2:19:12CP category ID so I am selecting posts
  2916. 2:19:17which are in this same category
  2917. 2:19:20the user upvote the current user app
  2918. 2:19:23voted posts
  2919. 2:19:25okay and I'm going to specify also we
  2920. 2:19:29don't want to grab the exact same post
  2921. 2:19:32user upvoted in the recommendations
  2922. 2:19:36so that's why we're going to exclude
  2923. 2:19:40t
  2924. 2:19:41which basically at the moment is the
  2925. 2:19:43upvoted pulse ID
  2926. 2:19:45T pulse ID
  2927. 2:19:48does not equal
  2928. 2:19:51to CP post ID
  2929. 2:19:55okay did you get the idea
  2930. 2:19:58okay if not feel free to pause and uh
  2931. 2:20:02listen to the section again so now we're
  2932. 2:20:04gonna grab
  2933. 2:20:06all the posts
  2934. 2:20:08from here now let's put semicolon here
  2935. 2:20:11and we select the post and now we need
  2936. 2:20:14to set bindings so here we use question
  2937. 2:20:17mark and we need to fill that question
  2938. 2:20:19mark by the currently authorized user ID
  2939. 2:20:23and finally let's call get on this and
  2940. 2:20:26have a look if I didn't mean miss
  2941. 2:20:28anything we should see some output of
  2942. 2:20:32recommended posts on the home page
  2943. 2:20:34so here we have that let's output
  2944. 2:20:37recommended
  2945. 2:20:40posts
  2946. 2:20:42save this and have a look
  2947. 2:20:44alt user with his auth manager user
  2948. 2:20:47undefined property okay this is this is
  2949. 2:20:51not a property it is a method
  2950. 2:20:55reload the page okay we have some syntax
  2951. 2:20:58error
  2952. 2:21:00okay we do have that
  2953. 2:21:03near post ID
  2954. 2:21:05from Apple downloads
  2955. 2:21:07okay let's double check everything
  2956. 2:21:11select from upload downloads join
  2957. 2:21:14category post on Apple downloads post ID
  2958. 2:21:18equals category post post ID
  2959. 2:21:20we are upvote downwards is up fault
  2960. 2:21:24equals one and apple downloads user ID
  2961. 2:21:26equals this one
  2962. 2:21:28okay this looks correct so this is a
  2963. 2:21:30left join section then front posts we
  2964. 2:21:33left you into category post as CP on
  2965. 2:21:36post ID equals to cppost ID
  2966. 2:21:40and then here we'll let join on this it
  2967. 2:21:44has nulliest TT
  2968. 2:21:45inside join we add the category ID needs
  2969. 2:21:49to be the same as the category post ID
  2970. 2:21:53and
  2971. 2:21:55the T post ID doesn't equal to category
  2972. 2:21:59posts
  2973. 2:22:00post ID
  2974. 2:22:02and then we select posts here
  2975. 2:22:06wasted bindings
  2976. 2:22:08then we return
  2977. 2:22:10okay where is an actual mistake
  2978. 2:22:14I didn't get it
  2979. 2:22:22okay we need to grab this
  2980. 2:22:25and execute this in the database client
  2981. 2:22:29to check if there is some mistake if
  2982. 2:22:33there's a mistake we are gonna know
  2983. 2:22:35about that
  2984. 2:22:39I know it's no mistake here instead of
  2985. 2:22:41left join yeah definitely we need to
  2986. 2:22:44specify DB row
  2987. 2:22:47so yeah of course
  2988. 2:22:50like in this case as you notice the
  2989. 2:22:53whole select is inside backtics it
  2990. 2:22:56assumed that there was a like database
  2991. 2:22:59expression column name or whatever but
  2992. 2:23:02we need this in to be a row row SQL so I
  2993. 2:23:06save this reload the page
  2994. 2:23:09and now we still have something not
  2995. 2:23:13correct
  2996. 2:23:16so let's check now
  2997. 2:23:18I'm going to grab this again
  2998. 2:23:23and execute here
  2999. 2:23:26and check what mistakes I have
  3000. 2:23:29okay here's something
  3001. 2:23:34here's something now where's the
  3002. 2:23:37database
  3003. 2:23:40here is the database
  3004. 2:23:49here is the problem
  3005. 2:23:52equals is missing isn't it
  3006. 2:23:55yes
  3007. 2:23:57join on category post on this where this
  3008. 2:24:00equals to this
  3009. 2:24:01so I save that reload the page and we
  3010. 2:24:05don't see her anymore which is awesome
  3011. 2:24:06and we see some recommended posts which
  3012. 2:24:09is even more awesome
  3013. 2:24:12okay
  3014. 2:24:13we get how many records we get here we
  3015. 2:24:17don't do obviously all records so let's
  3016. 2:24:20limit this into five
  3017. 2:24:24reload the page okay we see five records
  3018. 2:24:28here
  3019. 2:24:29we need to test if the actual result
  3020. 2:24:32outcome of your query is accurate but we
  3021. 2:24:36anyway need to render them and display
  3022. 2:24:38them so let me actually first do this
  3023. 2:24:44I'm going to use
  3024. 2:24:47a grid layout again for this let's give
  3025. 2:24:50it
  3026. 2:24:51read and grid columns
  3027. 2:24:54columns 1 and above medium screen let's
  3028. 2:24:57give it Creed
  3029. 2:24:59columns 3.
  3030. 2:25:02then we use for each recommended
  3031. 2:25:09posts as hosts and I'm going to use the
  3032. 2:25:13same component X post item in this case
  3033. 2:25:18let's specify
  3034. 2:25:20host here
  3035. 2:25:23actually let's select only three
  3036. 2:25:28here and here as well
  3037. 2:25:31so I save reload and just like this we
  3038. 2:25:36see latest three posts
  3039. 2:25:39well let's give it
  3040. 2:25:42gap of three maybe
  3041. 2:25:45just are broken which should not be but
  3042. 2:25:48that's not a big deal
  3043. 2:25:54okay
  3044. 2:25:59I don't think the design really fits to
  3045. 2:26:03anything else but
  3046. 2:26:06I guess we can leave this now I we just
  3047. 2:26:09can remove these parts it's not
  3048. 2:26:10necessary so let me actually show how to
  3049. 2:26:12remove this part so that we don't break
  3050. 2:26:14other components where this part is
  3051. 2:26:18actually necessary so I'm going to open
  3052. 2:26:20post item
  3053. 2:26:23component and inside the Constructor
  3054. 2:26:26let's accept wine property
  3055. 2:26:29public
  3056. 2:26:31let's make it Boolean
  3057. 2:26:33Boolean
  3058. 2:26:35let's call this
  3059. 2:26:39show
  3060. 2:26:42author
  3061. 2:26:44by default this is set to True show
  3062. 2:26:46author
  3063. 2:26:48public Boolean
  3064. 2:26:51it should be blue right show author
  3065. 2:26:55we we are using the following components
  3066. 2:26:58so in the post item we always show this
  3067. 2:27:01author we can write if statement if show
  3068. 2:27:06author
  3069. 2:27:07then we show it
  3070. 2:27:12and by default it is true so we
  3071. 2:27:15shouldn't see any difference
  3072. 2:27:18somewhere we have a semicolon which is
  3073. 2:27:20not necessary
  3074. 2:27:23okay by default it's it works in the
  3075. 2:27:25same way however in my home page when I
  3076. 2:27:28use that I can specify show author to be
  3077. 2:27:33false
  3078. 2:27:35and let's see what will happen
  3079. 2:27:38I don't see this author information here
  3080. 2:27:40okay however I see this above
  3081. 2:27:44again a great usage of component how you
  3082. 2:27:47can use it so that you don't break how
  3083. 2:27:50you can modify so that you don't break
  3084. 2:27:52anything else
  3085. 2:27:55okay now the question is why I see those
  3086. 2:27:57components why I see this in recommended
  3087. 2:28:01posts
  3088. 2:28:04well the idea was my query uh the idea
  3089. 2:28:07of my query was that two
  3090. 2:28:10to show only those posts which I have
  3091. 2:28:14upvoted and the other posts which are in
  3092. 2:28:17the same category I have reported so I
  3093. 2:28:19think I have upvoted this particular
  3094. 2:28:22post so I shouldn't actually be seeing
  3095. 2:28:24these posts so this we are close is
  3096. 2:28:28inside left join
  3097. 2:28:29and I guess this is not 100 accurate so
  3098. 2:28:34we should add right here additional wear
  3099. 2:28:38we are T post ID
  3100. 2:28:42does not equal to CP post ID
  3101. 2:28:47here we can use cppost ID or posts ID
  3102. 2:28:51it's going to be the same
  3103. 2:28:53so I save that reload the page
  3104. 2:28:56and we have something broken
  3105. 2:29:01let's see column T post ID
  3106. 2:29:08invalid parameter number
  3107. 2:29:14okay I think what we need to do instead
  3108. 2:29:16of this T post ID needs to be wrapped in
  3109. 2:29:20a DB row maybe because we have this t
  3110. 2:29:25inside DB row
  3111. 2:29:29like here this T Alias inside this DB
  3112. 2:29:33row so if I specify it like this
  3113. 2:29:36and we can let's change this into posts
  3114. 2:29:39ID
  3115. 2:29:41reload the page
  3116. 2:29:44invalid parameter number
  3117. 2:29:49is this actually a problem
  3118. 2:29:53like if I comment this out
  3119. 2:29:55yeah it works
  3120. 2:29:57if I uncomment this
  3121. 2:30:00it does not seem to be working
  3122. 2:30:12okay let's check what is the actual
  3123. 2:30:14select
  3124. 2:30:19this is Select
  3125. 2:30:21let's open and paste when to slow down
  3126. 2:30:25and understand what's going on
  3127. 2:30:27we are T post ID doesn't equal to
  3128. 2:30:30question mark why it is a question mark
  3129. 2:30:38well it should not be question right
  3130. 2:30:41okay let's do it vice versa
  3131. 2:30:44we are
  3132. 2:30:47that's it
  3133. 2:30:49post ID yeah we need to specify First
  3134. 2:30:52Column name
  3135. 2:30:53and then the column name operator and
  3136. 2:30:57right here we just we need this TV row
  3137. 2:30:59okay it should not be assumed that this
  3138. 2:31:01is a value instead we pass DB roll if I
  3139. 2:31:04save this and reload we see
  3140. 2:31:08yeah this is exactly what I wanted to
  3141. 2:31:10see so I see now two posts in my
  3142. 2:31:13recommended posts and those posts are in
  3143. 2:31:16the same category in the JavaScript
  3144. 2:31:18category I have upvoted one JavaScript
  3145. 2:31:21post and I see other two posts
  3146. 2:31:26recommended for me because I have 40
  3147. 2:31:28JavaScript posts this is awesome isn't
  3148. 2:31:30it so now if I go
  3149. 2:31:33and let's give this one this total
  3150. 2:31:36Managed IT okay whatever click edit
  3151. 2:31:39let's give it JavaScript as well
  3152. 2:31:42JavaScript category and when to make
  3153. 2:31:45this active
  3154. 2:31:46save enroll the page now we see this
  3155. 2:31:50here as well in my recommended posts the
  3156. 2:31:53image is broken not sure why
  3157. 2:31:57[Music]
  3158. 2:31:57um
  3159. 2:31:58here it wasn't actually broke was it
  3160. 2:32:01yeah whenever we update how whenever we
  3161. 2:32:04update it the image gets broken and this
  3162. 2:32:07is something probably we need to take
  3163. 2:32:10care of if I click on this and edit
  3164. 2:32:13I don't even see this image here even
  3165. 2:32:16though the image is presented here
  3166. 2:32:20okay we can take care of this this is a
  3167. 2:32:23slightly different problem not exactly
  3168. 2:32:25what we are trying to do at the moment
  3169. 2:32:27we're trying to make the home page uh
  3170. 2:32:30really active and working and now let's
  3171. 2:32:33focus on recent categories okay before
  3172. 2:32:36we move on the recent categories let me
  3173. 2:32:37move this comment up maybe
  3174. 2:32:41here for the else statement like this
  3175. 2:32:46and now let's do this so in this case I
  3176. 2:32:49want to select categories
  3177. 2:32:52category
  3178. 2:32:54query
  3179. 2:32:56where
  3180. 2:32:59um
  3181. 2:33:00hold on so I want to select category
  3182. 2:33:04with posts so I'm going to use weed
  3183. 2:33:08I want them with a post let's specify
  3184. 2:33:11any array here
  3185. 2:33:12with posts
  3186. 2:33:16I'm going to use function here we have
  3187. 2:33:19query
  3188. 2:33:20and then on the query I'm going to
  3189. 2:33:23Execute order by descending I want to
  3190. 2:33:27sort them by descending published it
  3191. 2:33:32okay perfect
  3192. 2:33:35we need to query basically only
  3193. 2:33:37categories like select categories
  3194. 2:33:42everything I want to also select
  3195. 2:33:47select select row I'll select role
  3196. 2:33:52um
  3197. 2:33:52like the maximum date so what's the idea
  3198. 2:33:56of the categories I should have probably
  3199. 2:33:57started from there so what categories I
  3200. 2:34:00want to show there I want to show the
  3201. 2:34:03categories
  3202. 2:34:05which contains the recently published
  3203. 2:34:09article so basically it turns out to be
  3204. 2:34:12a recent category because something
  3205. 2:34:14happened inside that category a new post
  3206. 2:34:17has been published like if there is a
  3207. 2:34:19PHP
  3208. 2:34:21category which has the latest post and
  3209. 2:34:24recently I published a new Post in the
  3210. 2:34:27JavaScript category the JavaScript
  3211. 2:34:29category will need to like need to be at
  3212. 2:34:32the top of these category lists
  3213. 2:34:36okay so in the select row I want to
  3214. 2:34:39select the maximum date of
  3215. 2:34:42uh we need join obviously so let's try
  3216. 2:34:46to join first
  3217. 2:34:47left and join
  3218. 2:34:50on category
  3219. 2:34:52category post
  3220. 2:34:54we are categories
  3221. 2:34:57ID
  3222. 2:34:59equals to
  3223. 2:35:01category post
  3224. 2:35:05um
  3225. 2:35:06category ID
  3226. 2:35:09okay
  3227. 2:35:10we need to also join
  3228. 2:35:14on posts
  3229. 2:35:18where
  3230. 2:35:19posts
  3231. 2:35:22ID
  3232. 2:35:23equals
  3233. 2:35:26to category
  3234. 2:35:28post
  3235. 2:35:30ID
  3236. 2:35:33and now we have from categories we
  3237. 2:35:37joined to category post and join to
  3238. 2:35:39posts and now I want to query what is
  3239. 2:35:42the maximum published it date
  3240. 2:35:48um let's give it an alias Max state
  3241. 2:35:50which is the maximum publish date for
  3242. 2:35:53that specific category okay and then I
  3243. 2:35:56want to order by descending by this Max
  3244. 2:36:00state so I order categories based on the
  3245. 2:36:04maximum date of its published posts
  3246. 2:36:09I hope this makes sense I can't explain
  3247. 2:36:12this any better
  3248. 2:36:13so Group by categories ID
  3249. 2:36:18and then we're going to limit this to
  3250. 2:36:20get the five categories and it should be
  3251. 2:36:23integer by the way I don't know why I
  3252. 2:36:24typo string
  3253. 2:36:26and
  3254. 2:36:28finally we call get
  3255. 2:36:30now I should have
  3256. 2:36:32top five categories
  3257. 2:36:35with
  3258. 2:36:36are sorted by the maximum published date
  3259. 2:36:39descending of those posts inside those
  3260. 2:36:43categories okay so I'm going to pass now
  3261. 2:36:47these categories to
  3262. 2:36:49to view let's do this
  3263. 2:36:52on its own line like this and now if we
  3264. 2:36:57go in the home blade this is the last
  3265. 2:37:00section what we are gonna implement
  3266. 2:37:04so we're going to iterate over
  3267. 2:37:06categories
  3268. 2:37:10is category
  3269. 2:37:13let's create div
  3270. 2:37:16we're gonna create H3 and let's output a
  3271. 2:37:21category
  3272. 2:37:25category title
  3273. 2:37:32and then we're going to iterate posts
  3274. 2:37:36and output those posts
  3275. 2:37:40so for this
  3276. 2:37:43um let's use Forge again
  3277. 2:37:45category
  3278. 2:37:47posts is post
  3279. 2:37:51let's create
  3280. 2:37:53I'm going to create one div again with
  3281. 2:37:56class read and grid calls uh calls one
  3282. 2:38:01and above medium let's give it grid
  3283. 2:38:05calls three
  3284. 2:38:06let's give it cap three as well
  3285. 2:38:09so this combines all the nested holes
  3286. 2:38:14and yeah for each post also we need only
  3287. 2:38:19for each category we also need like
  3288. 2:38:21three posts so
  3289. 2:38:23here probably order by descending we can
  3290. 2:38:26specify limit three as well
  3291. 2:38:30now we have three posts for each
  3292. 2:38:32category
  3293. 2:38:34and and I can use the exact same
  3294. 2:38:39component X post item passing post here
  3295. 2:38:46and we can also pass
  3296. 2:38:49um show author to be false we don't want
  3297. 2:38:52the author to be displayed
  3298. 2:38:55okay let's remove this extra div
  3299. 2:38:58and see what's going to be the output
  3300. 2:39:01below the page
  3301. 2:39:02okay we see laravel we see PHP those are
  3302. 2:39:06two categories
  3303. 2:39:07but we actually don't see items
  3304. 2:39:11here so if I print category posts let's
  3305. 2:39:15see what it is
  3306. 2:39:16yeah they are empty empty arrays
  3307. 2:39:21laravel and PHP why I don't see
  3308. 2:39:26why I don't see JavaScript
  3309. 2:39:29inside categories
  3310. 2:39:33okay strange so let's let's have a look
  3311. 2:39:36so from category let's if I remove this
  3312. 2:39:39with completely
  3313. 2:39:41okay so I select categories
  3314. 2:39:44I have this date left join everything
  3315. 2:39:48okay this looks good
  3316. 2:39:51reload the page I see no JavaScript here
  3317. 2:39:58okay I see something promising so let's
  3318. 2:40:02remove this and have a look so we see
  3319. 2:40:10hold on
  3320. 2:40:11recent categories here we here we go so
  3321. 2:40:13this is Javascript and all the
  3322. 2:40:15categories inside JavaScript
  3323. 2:40:18okay
  3324. 2:40:19then we have laravel and all the uh all
  3325. 2:40:22the posts excuse me from the laravel and
  3326. 2:40:25then we have PHP and all the posts from
  3327. 2:40:27PHP
  3328. 2:40:29okay
  3329. 2:40:31if I specify I want categories with
  3330. 2:40:35posts
  3331. 2:40:38if I just remove this weird
  3332. 2:40:43okay I still get that perfect
  3333. 2:40:47now if I Execute order by
  3334. 2:40:50um published it
  3335. 2:40:52in the limit three that completely
  3336. 2:40:54changes the picture so for JavaScript we
  3337. 2:40:57see that
  3338. 2:40:59but I think this limit three
  3339. 2:41:03is added
  3340. 2:41:06here
  3341. 2:41:07so it actually if I specify limit to one
  3342. 2:41:13now it works perfectly actually on
  3343. 2:41:17on JavaScript
  3344. 2:41:25well actually let's try to remove this
  3345. 2:41:28wave and in this case we should see
  3346. 2:41:32everything what we expect and in the
  3347. 2:41:35home blade
  3348. 2:41:37maybe I can execute get posts and
  3349. 2:41:40provide the limit here and get
  3350. 2:41:44the limits like a three
  3351. 2:41:47let's specify only with three here
  3352. 2:41:50okay if I reload
  3353. 2:41:54category
  3354. 2:41:56um that should be posts simply posts
  3355. 2:41:59okay now let's check this
  3356. 2:42:02uh recent categories we have JavaScript
  3357. 2:42:04three items for lateral one and for p if
  3358. 2:42:07you want so that actually works
  3359. 2:42:10keep in mind that right now we are
  3360. 2:42:13executing this query for each category
  3361. 2:42:16well at the moment we have only five
  3362. 2:42:18categories which is fine but if you have
  3363. 2:42:22X amount of categories in categories and
  3364. 2:42:27then you're going to execute
  3365. 2:42:29query for each category
  3366. 2:42:31uh you're gonna basically have a kind of
  3367. 2:42:35database issues not maybe issues but
  3368. 2:42:37you're gonna put extra load to the
  3369. 2:42:40database
  3370. 2:42:41so it's going to be good and I'm going
  3371. 2:42:42to do this to debug why these parts this
  3372. 2:42:47code doesn't work as expected I expected
  3373. 2:42:50it to limit posts
  3374. 2:42:54make a query for posts once and limit
  3375. 2:43:00uh limit for each category but yeah I
  3376. 2:43:02think we need to do it slightly
  3377. 2:43:04differently so that's why I'm going to
  3378. 2:43:05comment this out and again because this
  3379. 2:43:08is a home page and we have a limited
  3380. 2:43:09number of categories that's fine in my
  3381. 2:43:12opinion in this case
  3382. 2:43:13okay what we need to do
  3383. 2:43:18is
  3384. 2:43:19um either some formatting to
  3385. 2:43:23this
  3386. 2:43:26so this is like a text
  3387. 2:43:30text large
  3388. 2:43:32let's give it
  3389. 2:43:33text maybe Center
  3390. 2:43:40let's give this one also
  3391. 2:43:43margin button like all of them
  3392. 2:43:47plus margin button or
  3393. 2:43:51maybe here as well
  3394. 2:43:54margin button four
  3395. 2:43:59I think it should be
  3396. 2:44:01eight
  3397. 2:44:06uh okay and we have this
  3398. 2:44:09JavaScript here let's give it also font
  3399. 2:44:13bold
  3400. 2:44:14maybe even text the Excel
  3401. 2:44:22okay not too bad
  3402. 2:44:26give it margin bottom six
  3403. 2:44:34okay that's perfect like we have recent
  3404. 2:44:37categories
  3405. 2:44:40and yeah of course
  3406. 2:44:43that should work why it doesn't work
  3407. 2:44:46okay probably because this article is
  3408. 2:44:49not published
  3409. 2:44:50and we cut something
  3410. 2:44:53we don't specify here
  3411. 2:44:57in the home blade we don't specify
  3412. 2:45:02uh
  3413. 2:45:04that we need published posts
  3414. 2:45:08so if I open now post
  3415. 2:45:12and we have this
  3416. 2:45:16um
  3417. 2:45:17from category basically we have these
  3418. 2:45:19posts
  3419. 2:45:20I can Define one more that's going to be
  3420. 2:45:23published
  3421. 2:45:25posts
  3422. 2:45:27and we can run extra wear closes here
  3423. 2:45:31and I'm going to copy this again from
  3424. 2:45:34from here we are active in published
  3425. 2:45:37status in the past
  3426. 2:45:39like this
  3427. 2:45:41click ok
  3428. 2:45:44let's move this down
  3429. 2:45:46and in the home blade I'm going to use
  3430. 2:45:49published posts so if I say this now and
  3431. 2:45:53reload the page I don't see anything in
  3432. 2:45:56the lateral I see one PHP click on this
  3433. 2:45:59that works however we don't have laravel
  3434. 2:46:03category posts
  3435. 2:46:04published
  3436. 2:46:06and
  3437. 2:46:07if we go in the post controller
  3438. 2:46:11in the categories
  3439. 2:46:14it's good to add one extra as filter his
  3440. 2:46:19posts so basically if the category
  3441. 2:46:21doesn't have posts it doesn't make sense
  3442. 2:46:23to display it right here so if I just
  3443. 2:46:25refresh the page I should not see
  3444. 2:46:27lateral here but I see because it
  3445. 2:46:31actually has
  3446. 2:46:32one post and this has does not check
  3447. 2:46:38uh whether the post is published or not
  3448. 2:46:40so I think we can
  3449. 2:46:43and add an extra Wear close here
  3450. 2:46:48uh let's grab query
  3451. 2:47:00okay I don't know if we can this has if
  3452. 2:47:06that supports the filter okay laravel
  3453. 2:47:10uh we're
  3454. 2:47:14has something like this
  3455. 2:47:17I think there's I remember now so there
  3456. 2:47:20is something like where
  3457. 2:47:22has exactly like this we specify posts
  3458. 2:47:27and we specify function
  3459. 2:47:29like this
  3460. 2:47:31we get query here and then on that query
  3461. 2:47:35we run where category active and this
  3462. 2:47:41part and the publish that is in the past
  3463. 2:47:46okay now let's check this
  3464. 2:47:50refresh the page okay live will
  3465. 2:47:52disappeared exactly as we expected there
  3466. 2:47:54are no active posts in the laravel
  3467. 2:47:58category that's why it should not be
  3468. 2:47:59rendered if I open the page and search
  3469. 2:48:03for I don't know which one is
  3470. 2:48:06from laravel this one which is not
  3471. 2:48:09active
  3472. 2:48:10I activate this let's click edit
  3473. 2:48:14then active save changes go on the home
  3474. 2:48:17page refresh now we see laravel right
  3475. 2:48:20here
  3476. 2:48:22okay so this is our new home page we
  3477. 2:48:25have
  3478. 2:48:26latest post we have popular posts
  3479. 2:48:30we have recommended posts
  3480. 2:48:32for me and we have recent articles
  3481. 2:48:36JavaScript laravel PHP any file logout
  3482. 2:48:40recommended section should be different
  3483. 2:48:43now I see different output right here
  3484. 2:48:47okay I think this is this is really good
  3485. 2:48:52all right I'm gonna make small design
  3486. 2:48:55adjustments on the on the home page I'm
  3487. 2:48:58going to remove these recent categories
  3488. 2:49:00and instead put Javascript right here
  3489. 2:49:02and I'm going to also link it to the
  3490. 2:49:05actual categories page where you can
  3491. 2:49:07find all the JavaScript posts
  3492. 2:49:10and I'm going to also adjust the height
  3493. 2:49:13of the image because right here we see
  3494. 2:49:16that this one has smaller height this
  3495. 2:49:17one has large so let's make it fix give
  3496. 2:49:20it another like aspect ratio of like a
  3497. 2:49:23three by four or something like this and
  3498. 2:49:26then we we will be sure that we will
  3499. 2:49:28have the same hate for article and then
  3500. 2:49:31we will have title as well as the body
  3501. 2:49:35like I'm I have zoomed in very very
  3502. 2:49:37zoomed in
  3503. 2:49:38version in my browser that's why I have
  3504. 2:49:42a huge huge letters here and when you
  3505. 2:49:45zoom out actually it's going to be
  3506. 2:49:47tested in a hundred percent there there
  3507. 2:49:49might be necessary to adjust the font
  3508. 2:49:52size it says right Etc okay let's start
  3509. 2:49:54with small things and then then we're
  3510. 2:49:56gonna move on much much bigger thing
  3511. 2:49:58which gonna be implementing comments
  3512. 2:50:01comments section all right so let's open
  3513. 2:50:05um this blog and I'm gonna go in the
  3514. 2:50:09post item section
  3515. 2:50:14here
  3516. 2:50:17and yeah the post item component
  3517. 2:50:19basically is used on multiple places
  3518. 2:50:21right here and it is used right here and
  3519. 2:50:25we also have it used on the home page
  3520. 2:50:30um no on the inner page no this is
  3521. 2:50:33something else okay anyway so we have
  3522. 2:50:35this in two places right here and right
  3523. 2:50:37here so we need to give it a proper
  3524. 2:50:40aspect ratio to put the image properly
  3525. 2:50:44so let's give this one
  3526. 2:50:46um also out
  3527. 2:50:48there's going to be
  3528. 2:50:50post
  3529. 2:50:52title but speaking about the aspect
  3530. 2:50:55ratio let's search for
  3531. 2:50:57aspect ratio
  3532. 2:51:00Tailwind CSS there is one plugin
  3533. 2:51:04necessary to be installed I'm not sure
  3534. 2:51:06if this comes with the basic
  3535. 2:51:09installation
  3536. 2:51:12it might it might be coming
  3537. 2:51:16okay let's check
  3538. 2:51:19um we don't own Square
  3539. 2:51:23here we have that aspect Square we can
  3540. 2:51:27customize that and provide
  3541. 2:51:30three by four or four by three as we
  3542. 2:51:34want
  3543. 2:51:35or provide it like this like arbitrary
  3544. 2:51:38value this is what I want in classes for
  3545. 2:51:42the Post item
  3546. 2:51:44so let's give it aspect
  3547. 2:51:48three
  3548. 2:51:49by four no four by three we want it to
  3549. 2:51:52be in the landscape mode well that's why
  3550. 2:51:55let's specify 4x3 if we reload page we
  3551. 2:51:58see huge image okay the good thing is
  3552. 2:52:02that the hate now is always the same and
  3553. 2:52:05I think that's much better
  3554. 2:52:08but the images images very stretched
  3555. 2:52:12which we want to fix so if we specify
  3556. 2:52:15objects
  3557. 2:52:17cover
  3558. 2:52:19let's have a look
  3559. 2:52:21okay
  3560. 2:52:22now we don't see the whole image let's
  3561. 2:52:24specify object contain
  3562. 2:52:28okay I think this is what we want
  3563. 2:52:32so we have image always visible we have
  3564. 2:52:35three four by three which
  3565. 2:52:38which is kind of okay
  3566. 2:52:42however we can even customize this post
  3567. 2:52:45item component just like we customized
  3568. 2:52:49let me show you
  3569. 2:52:50so right here we have this show author
  3570. 2:52:52and in the same way we can add one extra
  3571. 2:52:54parameter which will Define the image
  3572. 2:52:57properties image aspect ratio whatever
  3573. 2:53:00we want and then we can use these for
  3574. 2:53:03um for like big size we can do
  3575. 2:53:07differently for uh for below we can do
  3576. 2:53:09it different like this is fine for me
  3577. 2:53:11but this is a little bit too large isn't
  3578. 2:53:15it
  3579. 2:53:20okay we can leave this at the moment I'm
  3580. 2:53:23going to leave it
  3581. 2:53:24one additional thing the images are
  3582. 2:53:27broken and that basically happens
  3583. 2:53:29because
  3584. 2:53:30we are using
  3585. 2:53:32seed data and we don't have actually
  3586. 2:53:35uploaded images
  3587. 2:53:37if I just click on this
  3588. 2:53:39and if I make some changes right here
  3589. 2:53:42then these images
  3590. 2:53:44is not going to be lost like
  3591. 2:53:46specified 2 here save that below the
  3592. 2:53:50page we see two right here but the image
  3593. 2:53:52is not lost images are only lost
  3594. 2:53:54whenever we update that specific article
  3595. 2:53:57which has that seed dummy URL right
  3596. 2:54:02there save changes go back and then this
  3597. 2:54:06is actually lost but that's fine because
  3598. 2:54:09we are not gonna spend time on to fix
  3599. 2:54:11some C data which is only created for
  3600. 2:54:14like demonstration purposes okay I think
  3601. 2:54:19we can move on the comment section uh
  3602. 2:54:22before that actually
  3603. 2:54:23um as I said I want to change these
  3604. 2:54:26recent categories how that is rendered
  3605. 2:54:28so I'm going to look for resend
  3606. 2:54:31categories here I have this on home page
  3607. 2:54:34and I'm going to move this for each
  3608. 2:54:38right right here
  3609. 2:54:42okay then this end for each goes out
  3610. 2:54:46right here so now I iterate over
  3611. 2:54:48categories instead of recent categories
  3612. 2:54:50I'm going to type the category title
  3613. 2:54:53right here
  3614. 2:54:55that's perfect and we also have these
  3615. 2:54:59uh continue reading icon Arrow icon I'm
  3616. 2:55:03going to copy this icon and put this
  3617. 2:55:05next to the category title
  3618. 2:55:10so if I say this now I see JavaScript
  3619. 2:55:12with the arrow and I'm going to make
  3620. 2:55:15this Arrow
  3621. 2:55:16to link on an actual category page
  3622. 2:55:20if we open web.php we see we have this
  3623. 2:55:24the following URL by category we need to
  3624. 2:55:26provide the category slug so let's use
  3625. 2:55:30root
  3626. 2:55:32by category and actual category
  3627. 2:55:36so I save this reload the page and if I
  3628. 2:55:38click this right now it opens the
  3629. 2:55:41category laravel and shows me all the
  3630. 2:55:43posts I have on laravel category which
  3631. 2:55:47is exactly what I wanted
  3632. 2:55:49okay I think this is awesome so we have
  3633. 2:55:53recommended posts and then JavaScript
  3634. 2:55:55okay I'm gonna add additional text right
  3635. 2:55:58here hosts for category
  3636. 2:56:03JavaScript
  3637. 2:56:05like this
  3638. 2:56:07here we go
  3639. 2:56:12pose for category JavaScript post for
  3640. 2:56:15category laravel and so on I think
  3641. 2:56:19category reliable this will be also good
  3642. 2:56:21enough
  3643. 2:56:22all right that's it for this video and I
  3644. 2:56:25hope you like it if so maybe you want to
  3645. 2:56:27hit the like button and maybe you want
  3646. 2:56:29to check my another project where I
  3647. 2:56:31created portfolio the codetholic.com in
  3648. 2:56:33laravel 9. you can find this video right
  3649. 2:56:36here thanks for watching and I will see
  3650. 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.