Archive of published posts by Adam Wathan

Testing Eloquent Models with Faktory

September 26, 2014

Eloquent is an ActiveRecord implementation, which means a lot of the time the behavior you’re adding to your models needs to hit the database to work correctly.

Imagine you a Customer model who has many Orders, and you need a way to get the orders for that customer that haven’t been shipped yet.

Read the rest of this post »

Using Bootstrap as a Mixin Library

June 6, 2014

If you’re already using Less for your custom stylesheets but importing Bootstrap as plain CSS, you’re missing out.

The Bootstrap website doesn’t do a great job of encouraging you to use their source Less files, but it makes it a lot easier to write clean, semantic markup.

Getting it setup in your project is also really simple, and if you do it right, you can actually get a nice reduction in file size.

Read the rest of this post »

The Virtual Proxy Pattern

May 13, 2014

When I was working on the relationship component of Faktory, I ran into a problem where telling a relationship to use a factory that wasn’t defined until later would blow everything up.

Faktory::define(['comment_with_post', 'Comment'], function($f) {
    $f->body = "Probably the greatest comment ever made.";
    $f->post = $f->belongsTo('post');
});

Faktory::define(['post', 'Post'], function($f) {
    $f->title = "My first post";
    $f->body = "Lorem ipsum dolor sit amet";
});

It would be annoying to have to define all of your factories in a carefully controlled order, so I needed to figure out a way to defer the loading of a factory until the relationship was actually being generated.

Read the rest of this post »

Introducing Faktory 0.1

May 6, 2014

Today we’re excited to announce the first release of Faktory.

Faktory is a library for easily setting up Eloquent models for your tests. It allows you to define reusable recipes for building your objects so that they always pass validation, while letting you override any properties that actually matter for what you’re testing.

Read the rest of this post »

There’s a model hiding in your REST API

April 11, 2014

REST is a great standard, but sometimes you need an endpoint that breaks convention.

Read the rest of this post »