0
0
Laravelframework~10 mins

Table naming conventions in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a Laravel migration for a table named correctly.

Laravel
Schema::create('[1]', function (Blueprint $table) {
    $table->id();
    $table->timestamps();
});
Drag options to blanks, or click blank then click option'
AUser
Buser
Cuser_table
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular table names like 'User'.
Adding extra words like 'user_table'.
2fill in blank
medium

Complete the code to specify the table name in a Laravel model.

Laravel
class User extends Model {
    protected $table = '[1]';
}
Drag options to blanks, or click blank then click option'
AUser
Buser_table
Cusers
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular or camel case names in the model.
Adding extra suffixes like '_table'.
3fill in blank
hard

Fix the error in the migration table name to follow Laravel conventions.

Laravel
Schema::create('[1]', function (Blueprint $table) {
    $table->id();
    $table->timestamps();
});
Drag options to blanks, or click blank then click option'
AUser
Busers
CuserTable
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular or camel case names.
Using inconsistent naming between model and migration.
4fill in blank
hard

Fill both blanks to create a migration for a pivot table between users and roles.

Laravel
Schema::create('[1]', function (Blueprint $table) {
    $table->foreignId('[2]_id')->constrained()->onDelete('cascade');
    $table->foreignId('role_id')->constrained()->onDelete('cascade');
    $table->primary(['[2]_id', 'role_id']);
});
Drag options to blanks, or click blank then click option'
Arole_user
Buser
Cusers
Duser_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular or camel case for pivot table name.
Using plural form in foreign key names.
5fill in blank
hard

Fill all three blanks to define a Laravel model with a custom table name and primary key.

Laravel
class Product extends Model {
    protected $table = '[1]';
    protected $primaryKey = '[2]';
    public $incrementing = [3];
}
Drag options to blanks, or click blank then click option'
Aproducts_custom
Bproduct_id
Cfalse
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using default table name instead of custom.
Not setting primaryKey when using custom keys.
Forgetting to set incrementing to false when needed.