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: An open-ended classic that shows how broad your understanding of the web is.
Answer
https), host and path.GET /jobs with headers and cookies.Go deeper on whichever part matches the role you are applying for.
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.
Why they ask this: Indexes are the first tool for slow queries; this checks real-world database thinking.
Answer
An index is a separate data structure (usually a B-tree) that lets the database find rows without scanning the whole table, much like the index at the back of a book.
Benefits: much faster WHERE, JOIN, ORDER BY and lookups on the indexed columns.
Trade-offs:
INSERT, UPDATE, DELETE) get slower because every index must be updated too.Composite indexes follow the leftmost-prefix rule: an index on (status, created_at) helps WHERE status = ? and WHERE status = ? ORDER BY created_at, but not WHERE created_at > ? alone.
CREATE INDEX jobs_status_created_at_index ON jobs (status, created_at);
EXPLAIN SELECT * FROM jobs WHERE status = 'open' ORDER BY created_at DESC;Use EXPLAIN to check whether a query actually uses an index.
Why they ask this: A favourite academic and interview topic in Nepal; it also shows you can design clean schemas.
Answer
Normalisation organises tables to remove duplicate data and the update problems it causes.
skills = "PHP, SQL"; use a separate row per skill.(student_id, course_id) → student_name, the name depends only on student_id, so move it to a students table.employees stores department_id and department_name, move the name to a departments table.Sometimes you denormalise on purpose for read performance, for example by storing a jobs_count on companies. Do it knowingly and keep the copy in sync.
Why they ask this: Payments and orders must never be half-saved; this checks you can protect data consistency.
Answer
A transaction groups several statements so that they all succeed or all fail together.
ACID:
DB::transaction(function () use ($order, $payment) {
$payment->update(['status' => 'paid']);
$order->update(['status' => 'confirmed']);
$order->product->decrement('stock', $order->quantity);
}); // any exception rolls back all threeClassic example: a bank transfer debits one account and credits another. Both must happen, or neither.
Why they ask this: Every frontend developer meets CORS errors when calling an API on another domain.
Answer
Browsers enforce the same-origin policy: JavaScript on https://app.example.com cannot read responses from a different origin (scheme + host + port), such as https://api.example.com, unless that server allows it.
CORS (Cross-Origin Resource Sharing) is how the server grants permission, using response headers such as:
Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Methods: GET, POST, PATCH, DELETE
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Allow-Credentials: trueFor non-simple requests (for example JSON bodies or an Authorization header) the browser first sends a preflight OPTIONS request.
Fix it on the server, not in the frontend: in Laravel, set allowed_origins in config/cors.php. Avoid * when cookies or credentials are involved; browsers reject that combination anyway. CORS is enforced by browsers only; Postman and server-to-server calls ignore it.
Why they ask this: Every team uses Git; this checks you can collaborate without rewriting shared history.
Answer
Both bring changes from one branch into another:
git merge main creates a merge commit that joins the two histories. Nothing is rewritten, so it is safe on shared branches, but the history shows every merge.git rebase main replays your branch's commits on top of main, creating new commits with new hashes. The result is a clean, linear history.git switch feature/login
git fetch origin
git rebase origin/main # update your feature branch
# fix conflicts, then: git add <file> && git rebase --continue
git push --force-with-lease # needed because history changedGolden rule: never rebase commits that other people have already pulled (such as main). Rebase your own feature branch; merge into shared branches, usually through a pull request.
Why they ask this: Tests whether you can design flexible code rather than only reciting definitions.
Answer
| Interface | Abstract class | |
|---|---|---|
| Contains | method signatures (and constants) | abstract and implemented methods, plus properties |
| A class can use | many interfaces | only one parent class (in PHP, Java and Dart) |
| Constructor and state | no | yes |
| Meaning | "can do" (a capability) | "is a" (a shared base) |
Cacheable, PaymentGateway.Report base class with an abstract rows() method.In PHP you can combine both, and use traits to share code horizontally. Dart has no interface keyword in older versions: every class can be implemented with implements, and Dart 3 adds interface class.