我已经创建了一个广告明细表,我想知道我应该在adDetail模型中使用哪种关系。迁移文件如下所示。请帮助我
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateAdsDetailsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('ads_details', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->unsignedInteger('ad_id');
$table->string('token', 60)->unique();
$table->longText('session_data');
$table->boolean('session_status')->default('0');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('ad_id')->references('id')->on('ads');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('ads_details');
}
}
答案 0 :(得分:0)
可能与广告和用户模型有关
在AdDetail模型中
public function ad()
{
return $this->belongsTo(Ad::class);
}
public function user()
{
return $this->belongsTo(User::class);
}