-
app/Models/Instance/Emotion/Emotion.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; class Emotion extends Model { // public function calls() { return $this->belongsToMany(Call::class, 'emotion_call', 'emotion_id', 'call_id') ->withPivot('account_id', 'contact_id') ->withTimestamps(); } // }
-
database/migrations/2018_12_09_145956_create_emotion_call_table.php
Open in GitHubuse Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateEmotionCallTable extends Migration { public function up() { Schema::create('emotion_call', function (Blueprint $table) { $table->unsignedInteger('account_id'); $table->unsignedInteger('call_id'); $table->unsignedInteger('emotion_id'); $table->unsignedInteger('contact_id'); $table->timestamps(); $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); $table->foreign('call_id')->references('id')->on('calls')->onDelete('cascade'); $table->foreign('emotion_id')->references('id')->on('emotions')->onDelete('cascade'); $table->foreign('contact_id')->references('id')->on('contacts')->onDelete('cascade'); }); } }