Anchor Diary Migrations

Play Video

Hi Guys, hope you’re well!
I’ve just been cracking on with coding laravel anchor in laravel.

I must confess I got a little bit ahead of myself. I’ve been meaning to do a screencast on each section of my progress but unfortunately I kind of forgot to do that and pushed ahead anyway!
But no matter, I’m going to double back and go through each of my steps that I took up to this date.

First step I took was migrations so I’m going to go through that today.
OK so, If you guys have never seen a migration before this is what one looks like in Laravel.

Basically what a migration is; is it’s a way of defining your database schema over time. So you know how you write an app and in a couple of months time the database might change (the schema might change). For example this title might become a longer title so it may need to become a text field.

So the idea of migrations is you can programmatically upgrade or downgrade the database depending on what you want to do at the time.

This function is called up it stands for upgrade (another way of thinking about this is this section here is moving forward in time) so this is Version 1.
You may have another one in future that edits the post table and that will create Version 2 of the database.

So what we’ve done is said we’re going to create a posts table and then we’re going to put inside of it a load of fields. So we’ve got things like a title which is a string, text for a description, timestamps, enum for a status with all its different statuses, comments, all sorts of things.

Then further down we have a function called down or downgrade (or going back in time as I like to think about it) and that basically drops the post table.

So if I run over to terminal now, so if I type in php artisan migrate lets see what happens.

So it said migration has been completed successfully and its then done a load of migrations in green text with a load of white text to say what it has migrated. So for example we have got 2013_11_06_create_post_table, now that refers to this file here, and we have all the other files too.

So lets take a look at our database, ok it looks like we haven’t got anything in it but if I refresh now we see theres a load of tables. So if we briefly take a look at that post table, now does that look a little bit familiar?

OK so we’ve got our ID, title, slug, description, html, css, javascript, timestamps, author, category, status, comments. They’re all in there they’re all the correct types and set appropriately with the right primary key ect ect. So that’s perfect.

But we haven’t demonstrated this ‘down’ section just yet so I’ll run through that with you.

So to go backwards we can do php artisan migrate:rollback, and that says it rolls back all of those migrations that I have done.

As you can see there’s only one table left the migrations table, which I forgot to mention the migration table basically keeps track of where we are (where the database is in relation to the migrations), so for each one of these it’ll list all the filenames and whether its done it or not.

And thats basically it for migrations, If you’d like learn more I recommend heading over to laracasts. There is a migrations lesson - migrations decoded, Jeffrey Way offers a fantastic explanation of migrations, much better than I’ve put across this has just been a quick overview, definitely recommend checking that one out.

Ok for now guys this is me.

I hope you have a good’en but for now see you later!

Anchor Cms In Laravel Part 1

Play Video

This took me an age to prepare, probably the hardest 3 minutes of my life but here it goes. The transcript is below incase anyone wants to read through.

Hi Guys, I’m Rob.

I’m a PHP Developer working at Box UK, Cardiff.

I’ve been working in PHP for the best part of 3 years and I’m a fond fan of the Laravel</a> framework, and also a proud early subscriber of Laracasts

So why am I here?

I’m hoping to do a series of screencasts to document my progress building Anchor CMS</a> in Laravel.

Now Laravel is a framework for web artisans. It’s super flexible and just great fun to work in (at least that’s my opinion).

Anchor CMS on the other hand is a really light weight CMS built in nano. It’s probably comparable to something like ghost where the content is written in Markdown and then it is processed and output to a screen.

The difference is this is written in PHP and contains a bit more functionality to do with pages and that whole side of things.

The problem with it though is it’s not really, well to be fair it was created at a time when PHP unit tests and testing in general wasn’t mainstream, not many people were talking about it.

In addition to that composer hadn’t really been created yet so it hadn’t been packaged up / dependency managed.

So the problems with it are that it’s not tested and nor is it very easy to update or extend.

So what am I hoping to achieve by doing these screencasts?

The first and the main goal for me is to improve my confidence and presentation skills. Hopefully by doing these I will be able to have the confidence to move out and start doing talks around Cardiff and elsewhere on various topics.

Another thing I hope to do is learn more about Laravel and how it works.

And finally for you guys hopefully give you inspiration on how I at least write my apps. I’ve noticed from the past that this has helped me by watching other people write apps from a higher perspective.

So thats about it guys,

Thanks for listening

Bye!

Using guard-phpunit with composer

While reading through a book on unit testing with PHP I ran into a few issues using guard with phpunit. This article guides me (and maybe you) through the process of installing & configuring guard with PHPUnit.

First of we need to install phpunit globally using composer. To do this create a new hidden directory called .composer/packages in your home folder

mkdir ~/.composer/packages

Then inside that directory create a new composer.json file and fill it with your global dependencies in our case phpunit

{
    "require": {
        "phpunit/phpunit": "3.7"
    }
}

Install phpunit by running composer install, this will install phpunit and all of its dependencies. After its completed we then need to edit our $PATH variable so we need to edit our ~/.bash_profile with the following

export PATH=$HOME/.composer/packages/vendor/bin:$PATH

Check that everything is working by running

phpunit --version

Which should return something like PHPUnit 3.7.21 by Sebastian Bergmann.

Wicked we have phpunit installed but now for guard & it’s phpunit extension. To do this run both these commands (you may have to sudo too)

gem install guard
gem install guard-phpunit

Now unless things have changed when you run guard you’ll receive this error

Call to undefined method PHPUnit_Framework_TestResult::allCompletlyImplemented()

It’s due to a small typo in the method name, so to change it find guard-phpunits source files in my case it was located here

/Library/Ruby/Gems/1.8/gems/guard-phpunit-0.1.4/lib/guard/phpunit/formatters/PHPUnit-Progress/PHPUnit/Extensions/Progress/ResultPrinter.php

In here find lines 250 and 256 and replace allCompletlyImplemented() with allCompletelyImplemented() Save and then run guard again.

I hope this helps anyone else in the same situation. All credit goes to this issue on Github