Laravel 5.2 - Create a database table from the controller

Sorry if this was asked, but I didn't seem to find the correct answer.

I need to create a table in the database from the controller.

I was naive to believe that below would work:

    Schema::connection('mysql')->create('mytable_'.$id, function($table)
    {
        $table->increments('id');
        $table->timestamps();
    });

Where $idis the dynamic value passed to the controller function.

I posted below on top:

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

No luck - how to create a database table from the controller? Any ideas?

Error: enter image description here

Solution As Ben Swinburne said in the first comment, use Schemano!

+4
source share
2 answers

You are using a facade Schema.

Make sure you have use Schema;the top of the file.

+2

, php artisan migrate :

Artisan::call('migrate');

, stubs, , - . , .

,

+1

All Articles