Drift

The personal blog of Phoenix-based developer Josh Janusch

Building a Blog in Laravel, Part 1

Building a Blog in Laravel, Part 1

This is the start of a series of posts I intend to write documenting my experiences and work in building a blog platform in Laravel

Over the last few weeks, I've wanted to build a larger project in Laravel outside of my job. After a lot of deliberation, I decided to go with a blog platform. The reasoning for that was simple:

  1. It's a simple task that can grow very large
  2. It can be used as a decent Laravel showpiece in my portfolio
  3. It let's me gain more experience in the framework I use day-to-day to build custom CRMs
  4. I can sit down and add new features when I have the time

This will be something I work on in my free time, hopefully a few hours a week after the initial build over my Thanksgiving vacation. I will attempt to write about all decisions I have to make as well as general architecture and functionality I am building.

The Goal

My initial goal for this phase is just the upper-level framework. The blog needs to be able to:

  1. List posts
  2. Run basic searches
  3. Manage users
  4. Create/Edit posts
  5. Organize posts by tags and categories
  6. Create/Edit single pages
  7. Use phpunit to test all pages and APIs, and perhaps other things as well

Nothing crazy for the first phase of the build, just the groundwork. As I mentioned, however, I want to be adding constantly adding new functionality. To this end, my further-reaching goals include:

  1. Integrating Algolia Search. Algolia is something I've wished to use for a few months now, since seeing a series on Laracasts detailing it. To start, however, this blog will use simple LIKE searches
  2. A robust dashboard that adds more complex post management, analytics, logging, etc. as well as integrates with Disqus, Google Analytics, and perhaps other SaaS such as Ottomatik.
  3. A media manager. A way to upload images, videos, files, etc. and include them in each post as well as a way to browse and include previously uploaded files.
  4. Different post types such as an Image or Video post.
  5. Integration with GitHub Gists
  6. Rework the interface to use Vue.js or React
  7. Integration with Twitter and other social networks for self-promotion

That's just a quick overview of my intentions. It would also be nice to, at some point, add theme and plugin support, although that is very low on my list of priorities.

Initial Decisions

I decided to build it in Laravel 5.1 on PHP 7 using Twig, Bootstrap, jQuery, Scss, Gulp, MySQL, and Homestead.

For the backend, I'd like to keep it up to date with Laravel updates as they are released, so I expect an update to 5.2 in the next month. I'm going with PHP 7 as a way to expose myself to it as well as get the improved performances. I'll use MySQL as the database for familiarity, although using Eloquent means I can easily switch to PostgreSQL or something else if I wanted to. I'm undecided what web server software I'll use at this time, though I suspect I'll stick to my usual Debian 8 with Apache 2.

For templating, I will use Twig instead of Blade. The reasoning behind this warrants an entire post, but suffice to say that it I do not agree with a few of the things that Blade can do and I like how strict and how little functionality Twig actually includes.

For front-end, I will use Bootstrap and jQuery. I know both well and they will do their job well enough. I had initially hoped to do this using Bootstrap 4, but it has been three months since the first alpha and there are glaring bugs in that alpha that make using it impossible right now. Hopefully, it will be possible to upgrade to 4 at some point in the near future.

I will also be using Sass (specifically Scss) for all of my custom styles and Gulp to compile it as well as the any Javascript classes I write. At this moment, I don't intend to use CoffeeScript or TypeScript or anything of that nature, but it could happen at a later time.

The other decision I made was that the post editor itself would be Markdown-based, perhaps with an adapter-based structure so that something like CKEditor could be used in its place at some other time. As I mentioned in Two Weeks With Ghost, I really enjoy using Markdown and I cannot fathom building a blog that does not utilize it.

I'm using Homestead for my local server just so I can be exposed to it. We do not use it at work and instead use a Vagrant box that matches our production environments. I want to use Homestead here just so I know how it works and what it does differently from our standard setup.

Naming

The project itself is unnamed at the moment, but I am leaning toward using Slip or Slipstream.

Current State

I've created the very basic database structure as well as the models for Posts, Tags, Categories, Users, etc. and controllers for Post and User management. Next up is basic route creation

Future

My plans are to work on this when I have some downtime at home, so progress may be slow. I will post new blog entries as progress is made. When the blog is in a working state, I'll release it on my GitHub.