getherbert / herbert

The WordPress Plugin Framework:
http://getherbert.com/
632 stars 94 forks source link

How Do You Check if a Table Already Exists? #121

Closed rooseveltrp closed 8 years ago

rooseveltrp commented 8 years ago

Hi,

Thanks for making this framework. I am having some trouble calling the Illuminate\Database\Schema\Builder::hasTable() method. Part of is my lack of familiarity with these classes.

It's resulting in a fatal error when I try to activate the plugin. All I am trying to do is, create the table if it doesn't exist :/

Here's what my activate.php file look like:

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

if (!Capsule::schema()->hasTable('sliders')) {
  Capsule::schema()->create('sliders', function($table) {
      $table->increments('id');
      $table->string('title');
  }); 
}

if (!Capsule::schema()->hasTable('slides')) {
  Capsule::schema()->create('slides', function($table) {
      $table->increments('id');
      $table->int('slider_id');
      $table->string('image_path');
      $table->string('effect');
      $table->int('delay');
  });
}
rooseveltrp commented 8 years ago

I found my error in the code. It should be $table->integer.