Skip to content

Database with Illuminate Models, Eloquent and migrations

License

Notifications You must be signed in to change notification settings

Morning-Train/wp-database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Morningtrain\WP\Database

A Morningtrain package that implements Laravel Eloquent and Migrations into WordPress.

Table of Contents

Introduction

Getting Started

To get started install the package as described below in Installation.

To use the tool have a look at Usage

Installation

Install with composer

composer require morningtrain/wp-database

Dependencies

illuminate/database

Database

Usage

Initializing package

<?php
    Database::setup(__DIR__ . "/database/migrations");

If you want to use migrations from multiple directories you can do, by calling the setup method multiple times.

Creating a Model

In app/Models

// Foo.php
<?php

    namespace MyProject\App\Models;

    /**
     * @property int $id
     * @property string $title
     */
    class Foo extends \Illuminate\Database\Eloquent\Model
    {
        public $timestamps = false;
        protected $table = 'foo';
    }

Creating a Migration

wp make:migration create_foo_table

If there is multiple migration paths, you will be asked to choose one.
Will create a new migration file for you with Schema::create('foo') already prepared.

Running migrations

You can run all new migrations like so:

Using wp cli:

wp dbmigrate

Using php:

<?php
    \Morningtrain\WP\Database\Database::migrate();
?>

Credits

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.

About

Database with Illuminate Models, Eloquent and migrations

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages