步骤
创建项目
laravel new one2one
安装Laravel debug利器
composer require barryvdh/laravel-debugbar --dev
创建Migration文件
php artisan make:model Profile -m
php artisan make:model Profile --migration
为此数据表文件添加外键字段
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProfilesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('profiles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('phone');
$table->unsignedInteger('user_id');
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('profiles');
}
}
迁移数据表
php artisan migrate