Part 5 - Database
PREREQUISITES
- Finished Laravel exercise -> Part 4 - Automation
- Finished Laravel -> Database migrations
- Finished Laravel -> Eloquent models
- Create the correct migrations and Eloquent models for the following database schema:
REMARKS
- The many side of the relationship always holds the foreign key
- A programme can have multiple students subscribed ->
programme_id
is defined in students table
- A programme can have multiple students subscribed ->
- A student can enroll in multiple courses AND a course can be followed by multiple students. This is a many-to-many relationship which we have to implement by using an associative table student_courses.
- If you use the command
php artisan make:model StudentCourse -m
, the corresponding database table will be named student_courses. According to the naming conventions, we also advice to usestudentcourses()
as the associated Eloquent hasMany relationship method.
- If you use the command
- Add some test data to these tables