Insights into Company
← PHP & Laravel

MVC, Blade and Routing

Understand the idea. Compare it. Explain it. Test yourself.

Question 1 of 9

Explain the Laravel MVC request lifecycle.

Solution and explanation

  • One of the most important questions for a 5-year developer.
  • For GET /api/products:
Web Server
    ↓
public/index.php
    ↓
Application Bootstrap
    ↓
Service Providers
    ↓
HTTP Kernel / Middleware Pipeline
    ↓
Router
    ↓
Route Middleware
    ↓
Controller
    ↓
Service
    ↓
Database
    ↓
Response
    ↓
Middleware
    ↓
HTTP Response
  • public/index.php is the entry point; it loads bootstrap/app.php, creates the application and sends the request through the HTTP kernel.
$app = require_once __DIR__.'/../bootstrap/app.php';
  • Interview tip: don't just say "the route calls the controller".
  • Walk through web server, index.php, bootstrap, service providers, middleware, router, controller, business logic, database and response.
Practice explaining this
Question 2 of 9

What belongs in routes/web.php?

Solution and explanation

  • web.php is for browser routes and runs the web middleware group: sessions, cookies and CSRF protection.
Route::get('/products', fn () => view('products'));
  • api.php is for stateless HTTP APIs.
  • Its routes are prefixed with /api and usually authenticate with tokens (for example Sanctum) instead of sessions.
  • In Laravel 11+ the file is added with php artisan install:api.
Route::get('/products', [ProductController::class, 'index']);
  • Typical API routes:
GET    /api/products
POST   /api/products
PUT    /api/products/{id}
DELETE /api/products/{id}
Practice explaining this
Question 3 of 9

What belongs in routes/api.php?

Solution and explanation

  • web.php is for browser routes and runs the web middleware group: sessions, cookies and CSRF protection.
Route::get('/products', fn () => view('products'));
  • api.php is for stateless HTTP APIs.
  • Its routes are prefixed with /api and usually authenticate with tokens (for example Sanctum) instead of sessions.
  • In Laravel 11+ the file is added with php artisan install:api.
Route::get('/products', [ProductController::class, 'index']);
  • Typical API routes:
GET    /api/products
POST   /api/products
PUT    /api/products/{id}
DELETE /api/products/{id}
Practice explaining this
Question 4 of 9

What is a controller responsible for?

Practice question · write your own answer
  • Define the concept in one or two sentences.
  • Give a small example and trace what happens.
  • Explain one limitation, trade-off, or common mistake.
Practice explaining this
Question 5 of 9

Where should business logic live?

Solution and explanation

  • MVC means Model, View, Controller.
  • Model: responsible for data and database interaction.
class Product extends Model
{
    protected $fillable = ['name', 'price', 'category_id'];
}
  • View: responsible for presentation.
<h1>{{ $product->name }}</h1>
<p>Price: {{ $product->price }}</p>
  • Controller: coordinates the request.
class ProductController extends Controller
{
    public function show(int $id)
    {
        $product = Product::findOrFail($id);

        return view('products.show', compact('product'));
    }
}
Request → Route → Controller → Model → Database → Model → Controller → View → Response
  • Important interview point: don't say "the model contains all business logic".
  • In a small application it might, but in a large production application responsibilities are separated:
Controller
   ↓
Service
   ↓
Repository / Query
   ↓
Model
Practice explaining this
Question 6 of 9

What is an Eloquent model?

Solution and explanation

  • Eloquent is Laravel's ORM (Object Relational Mapping).
  • Instead of SQL like SELECT * FROM products WHERE id = 10 you write:
$product = Product::find(10);

Product::create(['name' => 'Samsung A35', 'price' => 30000]);

$product->update(['price' => 28000]);

$product->delete();
Practice explaining this
Question 7 of 9

How does Blade render dynamic views?

Practice question · write your own answer
  • Define the concept in one or two sentences.
  • Give a small example and trace what happens.
  • Explain one limitation, trade-off, or common mistake.
Practice explaining this
Question 8 of 9

How do named routes keep navigation coordinated?

Practice question · write your own answer
  • Define the concept in one or two sentences.
  • Give a small example and trace what happens.
  • Explain one limitation, trade-off, or common mistake.
Practice explaining this
Question 9 of 9

How do CSRF and API authentication differ?

Practice question · write your own answer
  • Define the concept in one or two sentences.
  • Give a small example and trace what happens.
  • Explain one limitation, trade-off, or common mistake.
Practice explaining this