LARAVEL Research & Evidence-Based Practice 4 — Questions and Answers
Question 1: When research shows an application sends too many redundant HTTP requests to external APIs, which Laravel method caches the response with automatic TTL expiration?
- DB::remember()
- Cache::remember() (Correct answer)
- Http::withOptions()
- Response::cache()
Correct answer: Cache::remember()
Cache::remember() retrieves a cached value or executes a callback and stores the result for a given TTL.
Question 2: Which Laravel Telescope watcher should be enabled when researching unexpected Eloquent model state changes across a request lifecycle?
- QueryWatcher
- ModelWatcher (Correct answer)
- EventWatcher
- GateWatcher
Correct answer: ModelWatcher
Telescope's ModelWatcher records Eloquent model events (created, updated, deleted), revealing unexpected state mutations.
Question 3: According to Laravel's documentation on HTTP testing, which method puts the Http facade into a mode that prevents real outbound requests during tests?
- Http::mock()
- Http::fake() (Correct answer)
- Http::intercept()
- Http::stub()
Correct answer: Http::fake()
Http::fake() prevents actual HTTP requests and allows you to define stub responses for specific URL patterns.
Question 4: When profiling reveals slow Eloquent queries, which method inspects the raw SQL Eloquent will generate without actually executing the query?
- ->dump()
- ->toRawSql()
- ->dd()
- ->toSql() (Correct answer)
Correct answer: ->toSql()
->toSql() returns the raw SQL string with question-mark placeholders for bindings without executing the query.
Question 5: Which Laravel package performs static analysis to detect bugs, wrong type hints, and undefined variables without running the application?
- PHP_CodeSniffer
- Larastan (nunomaduro/larastan) (Correct answer)
- PHP Mess Detector
- Pint
Correct answer: Larastan (nunomaduro/larastan)
Larastan extends PHPStan with Laravel-specific rules, performing deep static analysis without executing the application.
Question 6: Which artisan command gives a high-level overview of the application's environment, loaded configuration, cache status, and installed packages?
- php artisan model:show
- php artisan make:inspect
- php artisan config:list
- php artisan about (Correct answer)
Correct answer: php artisan about
`php artisan about` shows environment, cache, drivers, and package information about the current Laravel installation.
Question 7: When researching test coverage for a Laravel application using Pest, which flag generates an HTML coverage report in a specified directory?
- --coverage-html=reports/ (Correct answer)
- --html-report=reports/
- --report html reports/
- --coverage-report html
Correct answer: --coverage-html=reports/
Running `./vendor/bin/pest --coverage-html=reports/` generates an HTML coverage report in the specified directory.
When research shows an application sends too many redundant HTTP requests to external APIs, which Laravel method caches the response with automatic TTL expiration?