Level 1
I found out, i didn't knew this was posible!
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateVideosTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// create categories table
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
//now create videos table
Schema::create('videos', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->default('');
$table->string('url')->default('');
$table->integer('category_id')->unsigned()->nullable();
$table->foreign('category_id')->references('id')->on('categories');
$table->string('img_url')->default('');
$table->integer('views')->nullable();
$table->integer('rating')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('videos');
Schema::dropIfExists('categories');
}
}
1 like