Filter by the role you are applying for, open a question, and practise explaining the answer out loud. Mark it practised when you can.
Why they ask this: The most common Eloquent performance bug; it shows you think about the queries your code runs.
Answer
The N+1 problem happens when you load a list (1 query) and then run one more query per item to load a relationship (N queries).
// 1 query for posts + 1 query per post for its author = N+1
$posts = Post::all();
foreach ($posts as $post) {
echo $post->author->name;
}Fix it with eager loading, which loads the relationship for all rows in one extra query:
$posts = Post::with('author')->get(); // 2 queries in total
$posts = Post::with(['author', 'comments'])->get();
$count = Post::withCount('comments')->get(); // comments_count without loading themFind N+1 problems with Laravel Debugbar or Telescope, or make them fail loudly in development with Model::preventLazyLoading(! app()->isProduction());.
Why they ask this: Middleware is how cross-cutting concerns like auth are handled; it shows you understand the request lifecycle.
Answer
Middleware is a layer that every matching HTTP request passes through before it reaches the controller, and the response passes back through after. Each middleware can let the request continue ($next($request)), change it, or stop it early.
Common uses:
auth / auth:sanctum reject guests./admin.throttle:60,1.class EnsureUserIsAdmin
{
public function handle(Request $request, Closure $next): Response
{
if (! $request->user()?->is_admin) {
abort(403);
}
return $next($request);
}
}
Route::middleware(['auth', EnsureUserIsAdmin::class])->group(function () {
Route::get('/admin', AdminDashboardController::class);
});Why they ask this: Security basics are non-negotiable for backend roles.
Answer
DB::select('select * from users where email = ?', [$email]). Never concatenate input into whereRaw.{{ $value }} escapes output with htmlspecialchars. Only use {!! $value !!} for HTML you have sanitised.@csrf inside Blade forms. Token-authenticated APIs (for example Sanctum tokens) are not exposed to CSRF in the same way.Also mention: mass assignment protection with $fillable, validation with Form Requests, hashing passwords with Hash::make (bcrypt or argon2), and authorisation with policies.
Why they ask this: Shows you know how to keep web requests fast and handle slow work reliably.
Answer
A job is a class that does one piece of work. A queue stores jobs so that a separate worker process (php artisan queue:work) runs them in the background.
Use queues for anything slow or unreliable that the user should not wait for:
class SendWelcomeEmail implements ShouldQueue
{
use Queueable;
public int $tries = 3;
public function __construct(public User $user) {}
public function handle(): void
{
Mail::to($this->user)->send(new WelcomeMail($this->user));
}
}
SendWelcomeEmail::dispatch($user);Queue drivers include database, redis and Amazon SQS. Failed jobs are stored and can be retried with php artisan queue:retry. In production, keep the worker running with Supervisor (or a platform's worker process) and restart it after each deploy.
Why they ask this: Most Nepali startups build an API for a React or mobile frontend, so you must know which auth fits.
Answer
Authorization: Bearer <token> header. This suits mobile apps and third-party clients.
In Laravel, Sanctum handles both: cookie-based SPA authentication for your own frontend and API tokens for mobile apps. Never store tokens where scripts can read them (such as localStorage) if you can use an httpOnly cookie instead.