0
0
Laravelframework~30 mins

Table naming conventions in Laravel - Mini Project: Build & Apply

Choose your learning style9 modes available
Table Naming Conventions in Laravel
📖 Scenario: You are building a simple Laravel application to manage books and authors. Laravel uses conventions to name database tables automatically based on model names.
🎯 Goal: Learn how to create tables with proper Laravel naming conventions and understand how Laravel links models to tables.
📋 What You'll Learn
Create a model called Book and understand its default table name
Create a model called Author and understand its default table name
Create a custom table name for a model
Use Laravel's migration files to define tables with correct names
💡 Why This Matters
🌍 Real World
Most Laravel applications use these naming conventions to keep code clean and predictable when working with databases.
💼 Career
Understanding Laravel's table naming conventions is essential for backend developers working with Laravel to build scalable and maintainable applications.
Progress0 / 4 steps
1
Create a Book model and migration
Run the artisan command to create a model called Book with a migration file. The migration will create a table named books by Laravel's default naming convention.
Laravel
Need a hint?

Use php artisan make:model Book -m to create both model and migration.

2
Create an Author model and migration
Run the artisan command to create a model called Author with a migration file. Laravel will create a table named authors by default.
Laravel
Need a hint?

Use php artisan make:model Author -m to create both model and migration.

3
Create a model with a custom table name
Create a model called Person with a migration. Then, inside the Person model file, set the protected property $table to 'people' to override Laravel's default table name.
Laravel
Need a hint?

Override the table name by adding protected $table = 'people'; inside the model class.

4
Define migration files with correct table names
Open the migration files for books, authors, and people tables. Ensure the Schema::create method uses the correct table names: books, authors, and people respectively.
Laravel
Need a hint?

Check each migration file uses Schema::create with the correct table name.