Ad

OctoberCMS: How To Access Database Tables After They Are Created?

- 1 answer

I need to access one of my database tables in the boot method of my plugin. The problem is that the first time that the plugin is installed, in the boot method, the tables have not been created yet, because the migration files are yet to be executed. So where is a safe place to access database tables the first time that my plugin is installed? How can I make sure that all migration files have been executed before accessing the database?

Ad

Answer

It's as simple as the following:

if (Schema::hasTable('my_plugin_table')) {
    $this->doSomeStuff();
}
Ad
source: stackoverflow.com
Ad