โ† All LARAVEL Flashcard Decks

Ultimate Laravel Flashcards

7 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 7 Ultimate Laravel flashcards as text
  1. Which Laravel command is used to run only the most recently created migration file?

    Answer: php artisan migrate --step=1

    `php artisan migrate --step=1` runs exactly one pending migration, which is the most recently created one.

  2. In Laravel Broadcasting, what interface must a model implement to broadcast its events on a private channel scoped to that model?

    Answer: Illuminate\Contracts\Broadcasting\HasBroadcastChannel

    Implementing `HasBroadcastChannel` and defining `broadcastChannel()` allows Eloquent models to expose a named private channel.

  3. Which Eloquent relationship method would you use to define a 'belongs to many' with an intermediate pivot table?

    Answer: belongsToMany()

    `belongsToMany()` defines a many-to-many relationship and expects a pivot table named by combining the two model names alphabetically.

  4. What is the default behavior of Laravel's `Route::resource()` when the model cannot be found during route model binding?

    Answer: It returns a 404 HTTP response

    By default, route model binding automatically returns a 404 response when the model is not found in the database.

  5. Which method allows you to add a global scope to an Eloquent model so it applies to every query on that model?

    Answer: boot() with addGlobalScope()

    Defining `addGlobalScope()` inside the model's `boot()` method registers a scope class or closure that applies to all queries.

  6. In Laravel, what is the role of a 'Policy' class?

    Answer: Centralizes authorization logic for a specific model or resource

    Policy classes group authorization logic (e.g., `view`, `create`, `update`, `delete`) for a given model and are registered with the Gate.

  7. What does calling `php artisan optimize:clear` do in a Laravel application?

    Answer: Clears all compiled/cached files including config, routes, views, and events

    `optimize:clear` runs all the individual `cache:clear`, `config:clear`, `route:clear`, `view:clear`, and `event:clear` commands at once.

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