LARAVEL Communication & Stakeholder Relations 5 — Questions and Answers
Question 1: A stakeholder API enforces a 60-second timeout. How do you configure this with Laravel's Http facade?
- Http::timeout(60)->get(url) (Correct answer)
- Http::withTimeout(60)->get(url)
- Http::setOption('timeout', 60)->get(url)
- Http::maxSeconds(60)->get(url)
Correct answer: Http::timeout(60)->get(url)
Http::timeout(60) sets the request timeout in seconds before an exception is thrown if the remote server doesn't respond.
Question 2: You need to broadcast an event only to users on a team channel. Which channel class and authorization approach is correct?
- new PublicChannel('team.{id}') with no auth
- new PrivateChannel('team.{id}') with a Broadcast::channel callback (Correct answer)
- new PresenceChannel('public.team') with no callback needed
- new SecureChannel('team.{id}') checked in middleware
Correct answer: new PrivateChannel('team.{id}') with a Broadcast::channel callback
PrivateChannel restricts subscriptions, and the authorization callback in routes/channels.php (Broadcast::channel) determines if the authenticated user can join.
Question 3: Which method on Laravel's Mailable class attaches an in-memory file (e.g., generated PDF) without saving it to disk?
- ->attach($path)
- ->attachFromStorage($disk, $path)
- ->attachData($data, $name, $options) (Correct answer)
- ->embedData($data, $name)
Correct answer: ->attachData($data, $name, $options)
attachData() lets you attach raw binary data directly to an email, ideal for dynamically generated files that you don't want to persist to disk.
Question 4: What does `Notification::fake()` allow you to assert in Laravel tests?
- That notifications were sent to specific notifiables without actually delivering them (Correct answer)
- That the notification queue worker is running
- That mail views render without errors
- That broadcast events fired on the correct channel
Correct answer: That notifications were sent to specific notifiables without actually delivering them
Notification::fake() intercepts notification dispatch so tests can assert with assertSentTo() without sending real emails, SMS, or Slack messages.
Question 5: A partner requires your API responses to include an `X-Request-ID` header for tracing. Where is the cleanest place to add it in Laravel?
- Inside every Controller method return statement
- In a dedicated Response middleware registered in the HTTP kernel (Correct answer)
- In the AppServiceProvider boot() method
- In the config/cors.php allowed_headers array
Correct answer: In a dedicated Response middleware registered in the HTTP kernel
A response middleware is the single, reusable place to append custom headers to every outgoing HTTP response without touching individual controllers.
Question 6: Which Laravel feature lets you send a notification to multiple notifiables (e.g., all admins) in a single call?
- Notification::sendNow($users, new AlertNotification())
- Notification::route('mail', $emails)->notify()
- Notification::send($notifiables, new AlertNotification()) (Correct answer)
- Notification::all()->notify(new AlertNotification())
Correct answer: Notification::send($notifiables, new AlertNotification())
Notification::send() accepts a collection or array of notifiables and a notification instance, dispatching it to all of them.
Question 7: A webhook from a payment provider includes a JSON body. Which is the correct way to verify HMAC-SHA256 signature in a Laravel controller?
- hash_equals(hash_hmac('sha256', $request->getContent(), $secret), $signature) (Correct answer)
- md5($request->getContent()) === $signature
- openssl_verify($request->getContent(), $signature, $secret)
- Crypt::decrypt($signature) === $request->getContent()
Correct answer: hash_equals(hash_hmac('sha256', $request->getContent(), $secret), $signature)
hash_equals() prevents timing attacks while hash_hmac('sha256', ...) computes the expected HMAC to compare against the provider's signature header.
A stakeholder API enforces a 60-second timeout.
How do you configure this with Laravel's Http facade?