Why they ask this: Every team project uses migrations; this checks you can work safely with a shared database schema.
Answer
Migrations are version control for the database schema. Each migration is a PHP class with an up() method that makes a change and a down() method that reverses it.
Schema::create('jobs', function (Blueprint $table) {
$table->id();
$table->foreignId('company_id')->constrained()->cascadeOnDelete();
Why they ask this: Shows you understand the core of the framework and can write testable, loosely coupled code.
Answer
Why they ask this: Most Nepali startups build an API for a React or mobile frontend, so you must know which auth fits.
Answer
Why they ask this: Indexes are the first tool for slow queries; this checks real-world database thinking.
Answer
Why they ask this: A common online-test question that checks you understand how GROUP BY queries run.
Answer
Why they ask this: Payments and orders must never be half-saved; this checks you can protect data consistency.
Answer
Why they ask this: Every developer calls or builds APIs; correct method use is a basic expectation.
Answer
Why they ask this: Correct status codes make APIs predictable for frontend and mobile developers.
Answer
Why they ask this: Most backend roles in Nepal build JSON APIs for web and mobile clients.
Answer
Why they ask this: Every frontend developer meets CORS errors when calling an API on another domain.
Answer
Useful commands: php artisan make:migration, migrate, migrate:rollback, migrate:status.
Why they are useful:
php artisan migrate.Never edit a migration that has already run in production. Create a new one instead.
Dependency injection (DI) means a class receives the objects it needs (its dependencies) from outside, usually through the constructor, instead of creating them itself. This makes code easier to test and swap.
The service container is Laravel's tool for building objects and their dependencies. It uses reflection on type hints to auto-resolve concrete classes, so this works with no configuration:
class InvoiceController
{
public function __construct(private InvoiceService $invoices) {}
}For interfaces, you tell the container which implementation to use, usually in a service provider:
$this->app->bind(PaymentGateway::class, KhaltiGateway::class);
$this->app->singleton(ExchangeRates::class, fn () => new ExchangeRates(config('services.nrb.url')));Benefits:
$this->app->instance(PaymentGateway::class, new FakeGateway).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.
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.
NULL, and a table has only one (it can span several columns, a composite key).ON DELETE CASCADE or SET NULL to decide what happens when the parent row is deleted.email. A table can have many. In MySQL and PostgreSQL a unique column can hold several NULLs.CREATE TABLE jobs (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
company_id BIGINT NOT NULL,
slug VARCHAR(255) NOT NULL UNIQUE,
FOREIGN KEY (company_id) REFERENCES companies(id) ON DELETE CASCADE
);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.
WHERE filters rows before grouping. It cannot use aggregate functions.HAVING filters groups after GROUP BY. It can use aggregates such as COUNT and AVG.-- Companies in Kathmandu with more than 5 open jobs
SELECT company_id, COUNT(*) AS open_jobs
FROM jobs
WHERE status = 'open' AND city = 'Kathmandu' -- row filter
GROUP BY company_id
HAVING COUNT(*) > 5; -- group filterThe logical order is FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT. Filter in WHERE whenever you can, because it reduces the rows that need grouping.
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.
| Method | Use | Safe | Idempotent |
|---|---|---|---|
GET | read a resource | yes | yes |
POST | create a resource or trigger an action | no | no |
PUT | replace a resource completely | no | yes |
PATCH | update part of a resource | no | not guaranteed |
DELETE | remove a resource | no | yes |
POST /orders calls can create two orders, while PUT /users/5 with the same body twice gives the same result.This matters for retries: clients and proxies can safely retry idempotent requests after a network error. For payments, use an idempotency key to make POST safe to retry.
200 OK, 201 Created (after a POST that creates something), 204 No Content (success with no body).301 Moved Permanently, 302 Found, 304 Not Modified (use the cached copy).400 Bad Request: malformed request.401 Unauthorized: not authenticated (no token or a bad token).403 Forbidden: authenticated but not allowed.404 Not Found.409 Conflict: for example a duplicate email.422 Unprocessable Content: validation errors (Laravel's default).429 Too Many Requests: rate limited.500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable.A frequent interview trap is the difference between 401 and 403.
REST (Representational State Transfer) is an architectural style for APIs built on HTTP. Key ideas:
/jobs, /jobs/42, /companies/7/jobs.GET /jobs lists, POST /jobs creates, PATCH /jobs/42 updates, DELETE /jobs/42 deletes.Content-Type.Good practice: version the API (/api/v1), paginate lists, use plural nouns and avoid verbs in URLs (POST /jobs/42/applications, not /applyJob).
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.