Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Which Artisan command is used to generate a new Eloquent model in Laravel?
Not quite. Try another option.
Answer: php artisan make:model ModelName
The command php artisan make:model ModelName creates a new Eloquent model class in the app/Models directory.
Question 2 of 50
By default, what table name will Laravel assume for a model named Flight?
Not quite. Try another option.
Answer: flights
Eloquent assumes that the table name is the "snake_case", plural form of the model name. Therefore, Flight maps to flights.
Question 3 of 50
If your database table does not follow the default naming convention, which property must be defined in the Model to specify the table name?
Not quite. Try another option.
Answer: protected $table
You can specify a custom table by defining a protected $table property on the model: protected $table = 'my_flights';.
Question 4 of 50
What is the primary purpose of Database Migrations in an MVC framework like Laravel?
Not quite. Try another option.
Answer: To serve as version control for the database schema
Migrations allow developers to define and share the application's database schema definition, acting effectively as version control for the database structure.
Question 5 of 50
Which method in a migration file is used to reverse the operations performed by the up method?
Not quite. Try another option.
Answer: down()
The down method should reverse the operations performed by the up method (e.g., dropping a table created in up).
Question 6 of 50
Which Artisan command executes all outstanding migrations?
Not quite. Try another option.
Answer: php artisan migrate
The php artisan migrate command runs all pending migrations to update the database schema.
Question 7 of 50
In the context of the Query Builder, which method is used to retrieve all rows from a table?
Not quite. Try another option.
Answer: get()
Using the Query Builder facade (DB::table(...)), the get() method returns an Illuminate\Support\Collection containing the results.
Question 8 of 50
When using Query Builder, how do you prevent SQL injection when adding a WHERE clause?
Not quite. Try another option.
Answer: By using Parameter Binding provided by the builder
The Laravel Query Builder uses PDO parameter binding effectively protecting the application against SQL injection attacks.
Question 9 of 50
What is the result of the following Query Builder code?
Answer: A single generic stdClass object representing the record
The first() method returns a single stdClass object representing the first row found, or null if no matching row exists.
Question 10 of 50
Which property in an Eloquent model allows you to specify which attributes are mass assignable?
Not quite. Try another option.
Answer: $fillable
The $fillable property is an array containing the names of attributes that are allowed to be mass assigned using methods like create() or update().
Question 11 of 50
Conversely, which property acts as a blacklist for mass assignment in Eloquent?
Not quite. Try another option.
Answer: $guarded
The $guarded property is an array of attributes that are not allowed to be mass assigned. If set to ['*'], all attributes are guarded.
Question 12 of 50
Which of the following describes the syntax to create a new record using Eloquent Mass Assignment?
Not quite. Try another option.
Answer: User::create(['name' => 'John']);
The create method inserts a new record into the database using mass assignment and returns the model instance.
Question 13 of 50
What is the purpose of Database Seeding?
Not quite. Try another option.
Answer: To populate the database with test or initial data
Seeding allows developers to populate the database with dummy data (for testing) or necessary initial data (like admin accounts) using seed classes.
Question 14 of 50
Which Artisan command creates a new Seeder class?
Not quite. Try another option.
Answer: php artisan make:seeder Name
The command php artisan make:seeder generates a new seeder class file in the database/seeders directory.
Question 15 of 50
When using Laravel with MongoDB, which library is commonly used to provide Eloquent-like functionality?
Not quite. Try another option.
Answer: jenssegers/mongodb
jenssegers/mongodb (now often maintained under mongodb/laravel-mongodb) is the standard package to enable Eloquent model functionality for MongoDB in Laravel.
Question 16 of 50
In a MongoDB Eloquent model, what class should the Model extend instead of Illuminate\Database\Eloquent\Model?
Not quite. Try another option.
Answer: Jenssegers\Mongodb\Eloquent\Model
To utilize MongoDB functionality, the model must extend the MongoDB-specific Eloquent class provided by the package (namespace varies by version, but historically Jenssegers\Mongodb\Eloquent\Model).
Question 17 of 50
What is the default primary key field name in MongoDB?
Not quite. Try another option.
Answer: _id
MongoDB uses _id as the default primary key field for documents.
Question 18 of 50
How do you handle migrations for MongoDB in Laravel given it is schema-less?
Not quite. Try another option.
Answer: Migrations are only used for creating indexes and unique constraints.
Since MongoDB is schema-less, migrations are not used to create tables or columns, but they are useful for defining indexes, unique constraints, or soft delete modifications.
Question 19 of 50
Which Eloquent method is used to retrieve a model by its primary key or throw an exception if not found?
Not quite. Try another option.
Answer: findOrFail()
findOrFail($id) retrieves the result by primary key or throws an Illuminate\Database\Eloquent\ModelNotFoundException if the record does not exist.
Question 20 of 50
In a REST API implemented with Laravel, which HTTP method corresponds to the update action?
Not quite. Try another option.
Answer: PUT/PATCH
In RESTful conventions, PUT is used for replacing a resource entirely, and PATCH is used for partial updates.
Question 21 of 50
When building an API, what is the standard HTTP status code for a successful resource creation?
Not quite. Try another option.
Answer: 201 Created
The 201 status code indicates that the request has been fulfilled and has resulted in one or more new resources being created.
Question 22 of 50
To transform Eloquent models into a specific JSON format for an API, what Laravel feature is recommended?
Not quite. Try another option.
Answer: API Resources
Eloquent API Resources provide a transformation layer that sits between your Eloquent models and the JSON responses returned to your application's users.
Question 23 of 50
Which file is specifically designated for defining API routes in a standard Laravel installation?
Not quite. Try another option.
Answer: routes/api.php
The routes/api.php file contains routes that are assigned the api middleware group, which includes features like statelessness and throttling.
Question 24 of 50
In Eloquent, how do you define a Soft Delete?
Not quite. Try another option.
Answer: Use the SoftDeletes trait in the model.
To enable soft deletes, you must use Illuminate\Database\Eloquent\SoftDeletes trait in the model and add a deleted_at column to the table.
Question 25 of 50
What is the equivalent of an SQL JOIN in Eloquent ORM?
Not quite. Try another option.
Answer: Relationships
Eloquent Relationships (like hasOne, hasMany, belongsTo) allow you to interact with related tables without writing manual JOIN queries.
Question 26 of 50
Which command would you use to rollback the very last migration operation?
Not quite. Try another option.
Answer: php artisan migrate:rollback
migrate:rollback rolls back the last "batch" of migrations, which may include multiple migration files run at the same time.
Question 27 of 50
When using the Query Builder, which method creates a raw expression that is injected into the query as-is?
Not quite. Try another option.
Answer: DB::raw()
DB::raw() allows you to insert raw SQL segments into your query. It should be used with caution to avoid SQL injection holes.
Question 28 of 50
In an API Controller, what method is conventionally used to show a single specific resource?
Not quite. Try another option.
Answer: show($id)
The show method is the standard resource controller method for displaying a specific resource identified by an ID.
Question 29 of 50
Which of the following is correct to delete a user with ID 1 using Eloquent?
Not quite. Try another option.
Answer: User::destroy(1);
User::destroy(1) allows deleting a record (or array of IDs) by primary key without retrieving the model first.
Question 30 of 50
If you are using MongoDB with Laravel, which operator is often used within where clauses for complex comparisons?
Not quite. Try another option.
Answer: MongoDB specific operators like '$gt', '$in'
While the wrapper supports many SQL-like methods, complex queries often utilize MongoDB operators (e.g., where('age', '>', 25) or where('age', '$gt', 25)).
Question 31 of 50
What does the timestamps() method create in a migration file?
Not quite. Try another option.
Answer: created_at and updated_at columns
The timestamps() helper creates two NULLABLETIMESTAMP columns: created_at and updated_at.
Question 32 of 50
In Eloquent, what is the default format for the $timestamps properties?
Not quite. Try another option.
Answer: Y-m-d H:i:s (String)
Eloquent casts the timestamps to instances of Carbon (which extends DateTime) and stores them as Y-m-d H:i:s strings in standard SQL databases.
Question 33 of 50
Which method enables you to call a seeder from within another seeder (e.g., inside DatabaseSeeder)?
Not quite. Try another option.
Answer: $this->call(Class::class);
The call method is used within the run method of a seeder to execute additional seed classes.
Question 34 of 50
When defining a foreign key in a migration, what does constrained() do in modern Laravel syntax?
Example: $table->foreignId('user_id')->constrained();
Not quite. Try another option.
Answer: It automatically determines the referenced table and column based on conventions.
constrained() uses the column name (e.g., user_id) to infer that it references the id column on the users table.
Question 35 of 50
Which return response is most appropriate for an API endpoint if a requested resource is not found?
A 404 HTTP status code explicitly tells the client that the requested resource could not be found on the server.
Question 36 of 50
What function is used to convert an Eloquent collection to a JSON string directly?
Not quite. Try another option.
Answer: toJson()
The toJson() method converts the collection (or model) into a JSON serialized string.
Question 37 of 50
Consider the equation for pagination offset: . Which Query Builder method handles this calculation automatically?
Not quite. Try another option.
Answer: paginate()
The paginate() method automatically handles setting the limit and offset based on the current page query parameter.
Question 38 of 50
In a MongoDB Laravel model, how are embedded documents usually accessed?
Not quite. Try another option.
Answer: As PHP arrays or objects accessed via dot notation
MongoDB stores embedded documents as nested BSON. In Laravel, these are accessed as arrays or objects, and dot notation can be used in queries (e.g., 'address.city').
Question 39 of 50
What is the purpose of Model Factories in the context of Seeding?
Not quite. Try another option.
Answer: To define a blueprint for generating fake data for models
Factories define a predictable set of attributes for a model, often using a library like Faker, making it easy to generate large amounts of test data in Seeders.
Question 40 of 50
Which query builder method is used to update an existing record?
Not quite. Try another option.
Answer: update()
DB::table('users')->where('id', 1)->update(['votes' => 1]); updates the records matching the condition.
Question 41 of 50
To use a specific database connection for a model other than the default, which property is used?
Not quite. Try another option.
Answer: $connection
The $connection property (string) on the model specifies the database connection name defined in config/database.php.
Question 42 of 50
In a REST API, what does the HEAD method do?
Not quite. Try another option.
Answer: Retrieves the resource headers without the body
HEAD is identical to GET except that the server creates a response without sending the entity-body. Useful for checking if a resource exists or has changed.
Question 43 of 50
When defining an Eloquent relationship, return $this->hasMany(Comment::class); implies what relationship structure?
Not quite. Try another option.
Answer: One-to-Many
hasMany indicates a One-to-Many relationship (e.g., A Post has many Comments).
Question 44 of 50
If you want to run a raw SQL query using the facade but do not need a return value (e.g., deleting), which method is used?
Not quite. Try another option.
Answer: DB::statement()
DB::statement executes a generic SQL statement (like DROP or generic DELETE/UPDATE) and usually returns a boolean indicating success.
Question 45 of 50
Which Artisan command generates a migration file specifically to modify an existing table?
Nearly through. Did unit 6 of INT221 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 6 of INT221 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.