PHP code example of bitsnio / json-to-migration-laravel
1. Go to this page and download the library: Download bitsnio/json-to-migration-laravel library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bitsnio / json-to-migration-laravel example snippets
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string("name", 50)->index();
$table->enum("state", ['active', 'inactive'])->default('active');
$table->text("text");
$table->string("slug", 50)->unique();
$table->boolean("active")->default(false);
$table->foreignId("user_id")->nullable(true)->constrained()->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('posts');
}
}
php artisan json:migrate schema.json