dongzhao5970 2019-02-26 19:09
浏览 27
已采纳

我需要在这个模型中做什么关系?

I have created a table for ad detail and I wondering which relation I should use in the adDetail model. The migration file looks like that. please help me

<?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');
    }
}
  • 写回答

1条回答 默认 最新

  • dongshuofu0039 2019-02-26 19:44
    关注

    probably a relation to Ad and User Model

    in AdDetail Model

    public function ad()
    {
    return $this->belongsTo(Ad::class);
    }
    public function user()
    {
    return $this->belongsTo(User::class);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?