<?php
//Migrations acts as a version control for the database allowing you to modify the app's database schema

//allows use of necessary libraries
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //checks if table already exists
        if(Schema::hasTable("users"))
            return;
        //if not, create a table with these fields
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name_first');
            $table->string('name_last');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->string("phone", 8)->unique();
            $table->rememberToken();
            $table->foreignId("resource_id")->nullable()->constrained("resources", "id");
            $table->boolean("wants_emails")->default(true);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */

    //if table exists, drop table.
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
