Reputation: 379
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?
Upvotes: 1
Views: 148
Reputation: 658
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
});
}
Upvotes: 1
Reputation: 486
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.
Upvotes: 1