How to Build a Blog with Laravel
Part 15 - Working with Dates from Database [How to Build a Blog with Laravel 5 Series]
Hide/Show description
See me in my natural habitat. Because of my busy schedule today I didn't have time to make a polished video for you guys like usual, so I am experimenting with a more Raw video where I make mistakes and have fewer edits. I go on a few tangents but decide to not edit them out. I hope you enjoy the video regardless of its potential flaws.
For today's topic we focus mainly on enhancing our posts.show page and working with dates from our database.
Dates in MySQL are stored as a string. However, PHP works with dates as a UNIX Timestamp. This is an integer of the number of seconds that have passed since Jan 1, 1970 UTC. Before we can do anything with dates, we need to first convert our database time string into something that PHP will work with.
To get a UNIX timestamp from a string you need to use strtotime() function from PHP. This converts it into an Integer unix timestamp.
Then to get the timestamp into a user friendly view, we need to use the PHP Date() command. This command will accepts a string formula as its first argument and a unix timestamp as its second argument. You can create the formula you want by looking on the PHP Date() website. I have the link below.
Next we work with Html::linkRoute() which allows us to give it a named route and it creates an html anchor tag (aka link). The first argument is the named route (string), the second is the value of the anchor tag, the third is an array (empty if no url params, or add the params in order), and the final argument is another array of all the options you want to use.
Last we talk about a fun app that downloads documentation for offline use. It is called Dash. Link below.
--- DOWNLOAD SOURCE CODE ---
https://github.com/jacurtis/laravel-blog-tutorial/releases/tag/part_15
--- LINKS ---
Bootstrap Well Docs:
http://getbootstrap.com/components/#w...
PHP Date() Docs:
http://php.net/manual/en/function.dat...
PHP StrToTime Docs:
http://php.net/manual/en/function.str...
Html::LinkRoute() Docs:
http://laravel-recipes.com/recipes/19...
Dash iOS and OS X App:
https://kapeli.com/dash_ios
--- MORE FROM THIS SERIES ---
Previous Video [Part 14]: https://youtu.be/0Qzi1yOoLBQ
Next video [Part 16]: Coming Soon
Full Playlist for the "How to Build a Blog with Laravel" Series: https://www.youtube.com/playlist?list...
--- FOLLOW ME ---
Subscribe for New Releases!
Twitter - http://twitter.com/_jacurtis
(ask me questions!)
--- QUESTIONS? ---
Leave a comment below and I or someone else can help you.
For quick questions you may also want to ask me on Twitter, I respond almost immediately.You can also email me [email protected]
Thanks for all your support!
---
Tags: Database date with PHP. Laravel 5.2 Framework Tutorial Easy to learn. Best tut about Laravel. Build a blog with Laravel Tutorial. Beginner tutorial. How to video. PHP framework easy best tutorial. Laravel 5 coding in PHP with Alex.
-
How to Build a Blog with Laravel - Part 1 (Exploring File Structure)
Part 2 - What is MVC [How to Build a Blog with Laravel 5 Series]
Part 3 - Getting Started [How to Build a Blog with Laravel 5 Series]
Part 4 - Controller Basics [How to Build a Blog with Laravel 5 Series]
Part 5 - Passing Data to a View [How to Build a Blog with Laravel 5 Series]
Part 5½ - Designing our Blog Pages [How to Build a Blog with Laravel 5 Series]
Part 6 - Layouts with Blade [How to Build a Blog with Laravel 5 Series]
Part 7 - Partials with Blade [How to Build a Blog with Laravel 5 Series]
Part 8 - Model Basics [How to Build a Blog with Laravel 5 Series]
Part 9 - Migration Basics [How to Build a Blog with Laravel 5 Series]
Part 10 - CRUD and RESTful Routes [How to Build a Blog with Laravel 5 Series]
Part 11 - "Create" function and Forms in Laravel [How to Build a Blog with Laravel 5 Series]
Part 12 - Inserting Data and Validating [How to Build a Blog with Laravel 5 Series]
Part 12½ - Javascript Form Validation [How to Build a Blog with Laravel 5 Series]
Part 13 - Sessions & Flash Messages [How to Build a Blog with Laravel 5 Series]
FAQs [How to Build a Blog with Laravel]
Part 14 - Reading from our Database [How to Build a Blog with Laravel 5 Series]
Part 15 - Working with Dates from Database [How to Build a Blog with Laravel 5 Series]
Part 16 - Read our CRUD [How to Build a Blog with Laravel 5 Series]
Part 16½ - Fixing a Bug, Making Navigation States work [How to Build a Blog with Laravel Series]
Part 17 - Model-Form Binding [How to Build a Blog with Laravel 5 Series]
Part 18 - Updating Form Data to Database [How to Build a Blog with Laravel 5 Series]
Part 19 - Deleting Resources with CRUD [How to Build a Blog with Laravel 5 Series]
Part 20 - Pagination in Laravel [How to Build a Blog with Laravel 5 Series]
Part 21 - Query Builder [How to Build a Blog with Laravel Series]
Part 22 - Adding Slug URLs to Our Blog [How to Build a Blog with Laravel Series]
Part 23 - Adding Slugs to our Posts CRUD [How to Build a Blog with Laravel 5 Series]
Parts 24 - Slugs in our URL Routes [How to Build a Blog with Laravel 5 Series]
Part 24 ½ - Fixing a Slug Bug [How to Build a Blog with Laravel Series]
Part 25 - Adding Features to our Blog Controller [How to Build a Blog with Laravel 5 Series]
Part 26 - Authentication Theory and Overview [How to Build a Blog with Laravel 5 Series]
Part 27 - Laravel Authentication Routes Views [How to Build a Blog with Laravel Series]
Part 28 - Authentication Methods [How to Build a Blog with Laravel 5 Series]
Part 29 - Authentication User Experience [How to Build a Blog with Laravel 5 Series]
Part 30 - Password Reset Emails [How to Build a Blog with Laravel 5 Series]
Part 30½ - Authentication Shortcut [How to Build a Blog with Laravel 5 Series]
Part 31 - Blog Categories and Learning Relationships [How to Build a Blog with Laravel 5 Series]
Part 32 - Categories CRUD [How to Build a Blog with Laravel Series]
Part 33 - Assigning Categories to Posts [How to Build a Blog with Laravel Series]
Part 34 - Many to Many Relationships [How to Build a Blog with Laravel 5 Series]
Part 35 - Building Our Tag Model [How to Build a Blog with Laravel 5 Series]
Part 36 - Starting our Tag CRUD [How to Build a Blog with Laravel 5 Series]
Part 37 - Adding Tag UI/UX [How to Build a Blog with Laravel 5 Series]
Part 38 - Show, Edit, Update our Tags [How to Build a Blog with Laravel 5 Series]
Part 39 - Deleting Tags Safely [How to Build a Blog with Laravel 5 Series]
Part 40 - Sending Email from Contact Form [How to Build a Blog with Laravel 5 Series]
Part 41 - Adding Comments [How to Build a Blog with Laravel 5 Series]
Part 41½ - Styling our Comments [How to Build a Blog with Laravel 5 Series]
Part 42 - Managing Comments [How to Build a Blog with Laravel 5 Series]
Part 43 - Adding a WYSIWYG Editor [How to Build a Blog with Laravel 5 Series]
Part 44 - Output HTML from Database [How to Build a Blog with Laravel 5 Series]
Part 45 - Security Concerns with WYSIWYG Editors [How to Build a Blog with Laravel 5 Series]
Part 46 - Image Upload for Posts [How to Build a Blog with Laravel 5 Series]
Part 47 - Validating, Updating, and Deleting Images [How to Build a Blog with Laravel 5 Series]