โ† All LARAVEL Flashcard Decks

LARAVEL Eloquent ORM & Database Flashcards

6 cards from real LARAVEL practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 6 LARAVEL Eloquent ORM & Database flashcards as text
  1. Which Artisan command creates a new Eloquent model along with its migration file?

    Answer: php artisan make:model Post -m

    The -m flag with make:model instructs Artisan to generate a corresponding database migration file simultaneously.

  2. What does the `$hidden` property do in a Laravel Eloquent model?

    Answer: Excludes listed attributes from array and JSON serialization

    Attributes listed in $hidden are omitted when the model is converted to an array or JSON, commonly used for passwords and tokens.

  3. How does Laravel's `updateOrCreate()` method work?

    Answer: It updates an existing record if found by the given attributes, otherwise creates a new one

    updateOrCreate() performs an upsert: it searches by the first argument's attributes and updates with the second, or creates if not found.

  4. What is a database migration in Laravel?

    Answer: A version-controlled PHP file that defines database schema changes

    Migrations are PHP classes that describe schema changes (create tables, add columns) in a version-controlled, reversible manner.

  5. Which method do you call to roll back the most recent batch of database migrations?

    Answer: php artisan migrate:rollback

    php artisan migrate:rollback reverses the last batch of migrations by calling the down() method on each migration file in reverse order.

  6. What is the purpose of Eloquent's `withTrashed()` method?

    Answer: To include soft-deleted records in a query result

    withTrashed() modifies the query scope to include records where deleted_at is not null, making soft-deleted rows visible.

How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy