Search code examples
laravelcommand-linedatabase-migration

How can I create table in database without using laravel default way using command line


I am trying to take input from user as table name, field list with their type (integer or text) and save that in on table and then create a table dynamically using that input.


Solution

  • i can assure you that you need to pick a newer way of doing your work, if you intend to work with Laravel then you need to work with Eloquent models big time. If you can you can share with us the idea and we can help you refine the logic. You should learn to use one table and find means to separate entries.

    However what you wanna do is achievable:

    Illuminate\Support\Facades\Schema::create('table_name', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('driver_id')->unsigned();
                $table->boolean('read_status')->default(false);
                $table->timestamps();
    
                $table->foreign('driver_id')
                    ->references('id')->on('drivers')
                    ->onDelete('cascade');
            });
    

    Something like this, you should customize it though