Using Laravel 4 + Eloquent With WordPress

Before I used Laravel, I used Codeigniter and I had the perfect workflow of being able to use WordPress as the administration panel, taxonomy system, authentication, users and post types.

I hate having to create administration panels from my previous experience working for a WordPress development agency, as the admin packages out there are complicated, don’t work correctly and are severely lacking in the features department.

In Laravel 4, the process for integrating WordPress is basically the same. You disable the theming functionality and include the WordPress blog-header bootstrapping file to include WordPress’ core functionality and features.

In the file public/index.php simply add the following:

define('WP_USE_THEMES', false);
require realpath(__DIR__.'/wordpress/wp-blog-header.php');

You now have WordPress integrated into your Laravel 4 installation. You can use functions inside of WordPress like wp_query, get_posts and more.

Using Laravel Eloquent With WordPress

Do you want to work directly with WordPress database tables using Eloquent? See below for an example to work with the wp_users table

attributes['user_pass'] = wp_hash_password($pass);
    }

}

Some things worth noting in the above example when using Laravel with a WordPress table is that WordPress uses ALLCASE “ID” as the primary key, the created and updated fields are different to what Laravel expects by default too.

Based on the above example, you should be able to work with other tables with ease. If you require examples, I can happily provide some more.