Skip to main content

Database

Eloquent

Database

An actual model layer in WordPress.

Introduction

This package implements Illuminate Database with a custom connection, that uses the global $wpdb instance for performing queries. What this means is that all queries, using the default driver and connection, goes through WordPress.

important

Not all Artisan Commands are supported yet. Run wp artisan to see what is available to you.

Getting started

First off, make sure the module is installed and set up.

Since this package mostly wraps Illuminate Database and sets $wpdb as the default connection, most of the Laravel documentation applies.

Migrations

Migrations allow you to customize the project database by creating and updating tables and more.

If you are not yet familiar with them then you should go read about them: Laravel docs.

Create a migration

wp artisan make:migration

Running migrations

wp artisan migrate
note

Migrations are located in /database/migrations/

Models & Eloquent

You can use Laravel Eloquent as you would in Laravel.

We recommend that your models are located in /app/Models/.

Queries

The Laravel Query Builder is available to use!

warning

We recommend that you still use WP_Query for querying WordPress data so that you still get the full effect of hooks, letting plugins extend them.