Building Web Apps with Laravel Module 11
Inside the framework interview questions
Interview questions on inside the framework: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher to mid
What does Laravel's service container do when a constructor asks for a class, and in which two cases does it need something from you?
Answered in the lesson The service container and dependency injection
-
Fresher to mid
What does Cache::get('fee-due:asha') call?
Answered in the lesson Service providers, facades and contracts
-
Fresher
What is the difference between map() and each() on a Laravel collection?
Answered in the lesson Collections, strings, numbers and dates
-
Fresher to mid
In Laravel, what is the difference between reporting an exception and rendering it?
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Mid to senior
Pathshala's GuardianNotifier now takes AttendanceAlerts in its constructor, and AttendanceAlerts takes GuardianNotifier. Neither is bound anywhere. Say what happens when a controller asks for either one, how you would find the cause, and how you would restructure the two classes.
- What it tests
- Whether the candidate knows that the container does not detect a constructor cycle, can read the symptom, and breaks the cycle by design rather than with a container trick.
- First step
- Write down the order in which autowiring would build the two classes, one constructor parameter at a time, and ask when that order ends.
- Follow-ups
-
- Why does a try and catch around the call that asks for GuardianNotifier not help?
- Which of the two classes should change, and how do you decide?
- When is an event a better way to break the cycle than a third class?
- How would a test find a cycle before it reaches production?
From the lesson The service container and dependency injection
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to staff
Each of Pathshala's three centres has its own merchant account with a card provider, and one centre still uses the sandbox. One queued job charges instalments for any centre. Design how code gets the right PaymentGateway for a given centre, and say what a container binding alone cannot do here.
- What it tests
- Whether the candidate separates a choice made once per process from one made per call, and keeps per-centre accounts from being cached under a shared key in a long-running worker.
- First step
- Ask when the choice is made: once at boot from config, or for every charge from the centre being charged. A binding answers the first; the second needs an object that takes the centre as an argument.
- Follow-ups
-
- Why is a closure binding that reads the current centre a poor fit?
- What goes wrong if you extend Laravel's Manager class and call driver('card') for every centre?
- Where should the merchant ids and keys live, and what must never print them?
- How do you test that two centres never share a gateway inside one worker?
From the lesson The service container and dependency injection
Model answer, Pro.In the answer:
- Model answer
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
To speed up web requests, a teammate makes FeeServiceProvider deferred. It binds FeeCalculator in register and, in boot, listens for InstalmentPaid to email a receipt. Some web requests now record a payment but send no receipt, while the nightly command always sends them. Explain both behaviours and fix the design.
- What it tests
- Whether the candidate knows when a deferred provider loads in web requests and in Artisan processes, and keeps listeners out of deferred providers.
- First step
- Ask which requests ever ask for a FeeCalculator, and what the nightly command does differently when it starts.
- Follow-ups
-
- Why does the nightly command never miss a receipt?
- Where should the listener live instead, and what may stay deferred?
- Why did the feature tests stay green, and what test would have failed?
From the lesson Service providers, facades and contracts
Model answer, Pro.In the answer:
- Model answer
- Common mistakes
- Rubric
- Variants
- about 2 minutes
-
Mid to senior
A feature test calls Mail::fake(), records a payment and asserts Mail::assertSent(FeeReceipt::class), but the assertion fails although the receipt code ran. ReceiptMailer is a singleton built in AppServiceProvider::boot that keeps the mailer it receives. Explain what the fake replaced, and give two fixes.
- What it tests
- Whether the candidate knows that a fake replaces only what is resolved after it, and fixes the code rather than the test.
- First step
- Write down the order of events: when ReceiptMailer was built and which mailer it received, then when the test installed the fake and what that call replaced.
- Follow-ups
-
- What exactly does Mail::fake() replace, and where?
- Why does moving Mail::fake() to the first line of the test not help?
- Which change to ReceiptMailer works in tests and in production alike?
- Would Storage::fake() behave the same for a class that keeps a disk?
From the lesson Service providers, facades and contracts
Model answer, Pro.In the answer:
- Model answer
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
You are turning Pathshala's receipt numbering into a Composer package used by several Laravel apps. Decide how its classes reach the cache and the config, whether it ships a facade, and how it registers itself. Defend each choice for testing, for long-running workers and for apps that do not want the facade.
- What it tests
- Whether the candidate separates a package's internals from its convenience API, uses contracts and a discovered provider, and plans for tests and long-running processes.
- First step
- List the package's dependencies and its public entry points separately, then choose for each dependency the most general type that Laravel binds for it.
- Follow-ups
-
- Why contracts inside the package rather than facades?
- Should the package's provider be deferred?
- How does an app use the package without its facade, and how do its tests replace it?
- What must the package avoid keeping in a singleton?
From the lesson Service providers, facades and contracts
Model answer, Pro.In the answer:
- Model answer
- Common mistakes
- Rubric
- Variants
- about 2 minutes
-
Mid to senior
Pathshala's centres in India want a "collected today" figure on the dashboard and a daily total for the last 30 days. Payments are stored in UTC. A teammate groups by DATE(paid_at) in SQL. Explain what goes wrong, and design the query and the test.
- What it tests
- Whether the candidate turns local days into UTC ranges, keeps the database in UTC, and tests the hours where the two calendars disagree.
- First step
- Write down when a day in India starts and ends, expressed in UTC, and compare it with the day that DATE(paid_at) produces.
- Follow-ups
-
- Which payments land on the wrong day, and how many hours of each day are affected?
- How do you write "today" for the dashboard without converting every row?
- How do you group 30 days in SQL so that each bucket is a day in India?
- Which test cases would catch a regression?
From the lesson Collections, strings, numbers and dates
Model answer, Pro.In the answer:
- Model answer
- Common mistakes
- Rubric
- Variants
- about 2 minutes
-
Mid to senior
An accountant's "download all payments" button builds a CSV with Payment::all()->map(...) and fails with "Allowed memory size exhausted" once the table passes a few hundred thousand rows. Rewrite the export so its memory does not grow with the table, and say what you would measure.
- What it tests
- Whether the candidate streams both the reading and the response, picks a reader that suits the table, and proves the fix with a measurement rather than a guess.
- First step
- Find the two places where the whole year is held at once: the query result and the CSV string. Each needs its own streaming answer.
- Follow-ups
-
- Which reader would you pick, and why not cursor() for every case?
- How does the response avoid holding the CSV in memory?
- What happens to payments recorded while the export runs?
- How do you show in a test that memory no longer grows with the rows?
From the lesson Collections, strings, numbers and dates
Model answer, Pro.In the answer:
- Model answer
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to senior
A course fee of 10,000 rupees is split into 3 equal instalments, and the report adds the instalments of 1,200 students. A developer stores amounts as floats in rupees and rounds when printing. Explain what goes wrong and how you would store, split and total the money.
- What it tests
- Whether the candidate keeps money in integer minor units, distributes a remainder explicitly, and formats only at the edge.
- First step
- Split 10,000 rupees into three parts by hand, to the paisa, and check whether the parts add back up to the fee.
- Follow-ups
-
- Why does a float total drift, and when does the drift show?
- Where does the remaining paisa go when 1,000,000 paise does not divide by 3?
- Which collection methods compute the totals, and where does Number come in?
- How would a test catch a split whose parts do not add up?
From the lesson Collections, strings, numbers and dates
Model answer, Pro.In the answer:
- Model answer
- Common mistakes
- Rubric
- Variants
- about 2 minutes
-
Mid to senior
A parent emails Pathshala a screenshot of an error page that shows a file path, a SQL query and some configuration values. Production was deployed an hour ago. Say what you do in the first hour, and what stops it from happening again.
- What it tests
- Whether the candidate contains the leak, treats every value the page could show as exposed, and adds a check that fails a deploy instead of relying on care.
- First step
- Work out which setting produced the page: a stack trace on a public 500 means debug mode is on in that environment. Then list every value such a page could have shown to anyone who triggered an error.
- Follow-ups
-
- Why might switching APP_DEBUG off in the environment file change nothing at first?
- Which secrets do you rotate, and in what order?
- What check would have stopped the deploy?
From the lesson Errors, logging and context
Model answer, Pro.In the answer:
- Model answer
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to staff
A guardian says a payment went through yesterday evening but no receipt SMS arrived. Pathshala runs three web servers and two queue workers, all logging JSON to standard error. Design logging that lets support answer in five minutes, and say what must never appear in those lines.
- What it tests
- Whether the candidate joins web and worker lines with one id carried by context, logs actions and outcomes rather than secrets, and knows where hidden values still end up.
- First step
- List the events between the click on Pay and the SMS, note which process writes each one, and ask which single value could join them all.
- Follow-ups
-
- How does the request id reach the worker's lines?
- What does each line need so that support can search it?
- Which values stay out of the lines, and how is that enforced?
- Where else do hidden values end up?
From the lesson Errors, logging and context
Model answer, Pro.In the answer:
- Model answer
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
During an SMS provider outage, Pathshala's error tracker receives 4,000 timeout reports an hour, and a new bug in fee calculation goes unnoticed for a day. Change the reporting rules so the outage stays visible without drowning everything else, and say what parents see meanwhile.
- What it tests
- Whether the candidate throttles by kind instead of silencing it, keeps the first occurrences, raises what matters, and renders a useful message to users.
- First step
- Separate three needs: knowing when the outage started and ended, still seeing every other new error, and telling the parent what happened to the receipt.
- Follow-ups
-
- Why not add the timeout to dontReport?
- A limit or a lottery, and why?
- How do you keep the fee-calculation bug from being throttled with it?
- What does the parent see, and what happens to the SMS?
From the lesson Errors, logging and context
Model answer, Pro.In the answer:
- Model answer
- Common mistakes
- Rubric
- Variants
- about 2 minutes
All Building Web Apps with Laravel interview questions · The Building Web Apps with Laravel track