How to create project_user pivot table in laravel

Created at 23-Jul-2021 , By samar

How to create project_user pivot table in laravel

With this article, we’ll look at some examples of how to address the "How to create project_user pivot table in laravel" problem.

You can create a project_user pivot table in laravel using migration. project_user table is the pivot table used to store pivot column data with extra columns in laravel
  • Create project_user pivot table with additional column is_manager and order_by

    php artisan make:migration create_project_user_table --create=project_user
    
    //database\migrations\<2021_07_21_080148>_create_project_user_table.php
    <?php
    
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    class CreateProjectUserTable extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::create('project_user', function (Blueprint $table) {
                $table->foreignId('project_id')->constrained();
                $table->foreignId('user_id')->constrained();
                $table->boolean('is_manager')->default(false);
                $table->boolean('order_by')->nullable();
                $table->timestamps();
            });
        }
    
        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down()
        {
            Schema::dropIfExists('project_user');
        }
    }
    
    php artisan migrate
    

Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.