Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Created February 3, 2026 17:52
Show Gist options
  • Select an option

  • Save ziadoz/dd11b6cc4fe65b8914739105cbb1d812 to your computer and use it in GitHub Desktop.

Select an option

Save ziadoz/dd11b6cc4fe65b8914739105cbb1d812 to your computer and use it in GitHub Desktop.
Laravel 12.x - Many-to-Many Join Table Structure
<?php
use App\Models\Movie;
use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('user_movies', function (Blueprint $table) {
$table->foreignIdFor(User::class)->constrained();
$table->foreignIdFor(Movie::class)->constrained();
$table->primary(['user_id', 'movie_id']);
});
}
public function down(): void
{
Schema::dropIfExists('user_movies');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment