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 starting point for any Laravel interview; it shows you know where code belongs.
Answer
MVC (Model–View–Controller) separates an application into three parts:
app/Models), each mapped to a database table.resources/views), or JSON from API Resources in an API.app/Http/Controllers).The flow: route (routes/web.php or routes/api.php) → middleware → controller → model → view or JSON response.
Route::get('/jobs/{job}', [JobController::class, 'show']);
class JobController extends Controller
{
public function show(Job $job) // route model binding
{
return view('jobs.show', ['job' => $job]);
}
}In bigger apps, keep controllers thin and move business logic into service or action classes.
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: Joining tables is daily backend work and a staple of online tests in Nepal.
Answer
NULL.UNION.-- Every company, with its job count (including companies with no jobs)
SELECT c.name, COUNT(j.id) AS jobs
FROM companies c
LEFT JOIN jobs j ON j.company_id = c.id
GROUP BY c.id, c.name;Note that COUNT(j.id) counts only matched rows, while COUNT(*) would count 1 for a company with no jobs.
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: 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();
$table->string('title');
$table->unsignedInteger('salary_min')->nullable();
$table->timestamps();
});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.
Why they ask this: Shows you understand the core of the framework and can write testable, loosely coupled code.
Answer
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).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: Checks that your PHP knowledge is current and not stuck in PHP 5-era habits.
Answer
public function find(int $id): ?User.public function __construct(private UserRepository $users) {}.str_pad(string: $code, length: 6, pad_string: '0', pad_type: STR_PAD_LEFT).match expression: strict comparison and returns a value, unlike switch.$user?->profile?->phone.enum Status: string { case Active = 'active'; }.readonly properties (8.1) and readonly classes (8.2) for immutable value objects and DTOs.array_map($this->format(...), $rows).get/set logic declared on a property.enum JobType: string
{
case FullTime = 'full_time';
case Internship = 'internship';
public function label(): string
{
return match ($this) {
self::FullTime => 'Full time',
self::Internship => 'Internship',
};
}
}Why they ask this: Core relational design knowledge for any backend role.
Answer
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
);