1

I have a database table teacher_attendances, with field:

id, name, data, attendance.

I try to generate a pivot table based on teacher_attendances table.

I want rowname as TeacherName and columnname as Date and cloumnname below mark attendance.

How to create pivot table in Laravel 4?

2 Answers 2

1

Have you checked out Laravel Migration and Schema Builder Documentation?

Run php artisan migrate:make create_teacher_attendances_table --create --table=teacher_attendances in the CLI to generate the file.

Then edit the file to include something like this up method

public function up()
{
    Schema::create('teacher_attendances', function(Blueprint $table)
    {
        $table->increments('id');
        // Your code here
    });
}

Don't forget about foreign-keys.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to execute following command:

php artisan make:migration create_attendance_teacher --table="attendance_teacher"

Note : create_attendance_teacher is taken singular form for the tables attendances & teachers respectively.
As per convention try to create pivot table alphabetical order. Hence we took attendance table before teachers table.

Then, in migration script:

public function up()
{
    Schema::create('teacher_attendances', function(Blueprint $table)
    {
        $table->increments('id');
        $table->integer('attendance_id');//Foreign key from attendances table
        $table->increments('teacher_id');////Foreign key from teachers table
    });
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.