Skip to the workspace
Pebellslearn by building
Getting Started with Laravel  ›  Lesson

Why Web Frameworks?

Why Web Frameworks? 12 minA web framework hands you tested answers to the jobs every web app repeats, such as routing, sessions, database access and security, so your own code can focus on what makes the app different.

laravel / Why Web Frameworks?

Explore each scene at your own pace.

01 · The rule

The rule

Why Web Frameworks?

Picture building Lendly, a small app where neighbours lend each other books. Before you write a single line about books or loans, you already need URLs that map to code, logins that remember people, forms that reject bad input and a safe way to talk to the database. Every web app needs those same pieces. A framework is where they come pre-built.

The rule

A framework solves the repeated jobs so you solve the unique one.

Almost every web app repeats the same chores:

  • Routing: turning GET /books/42 into "run the code that shows book 42".
  • State: sessions and cookies so the app remembers who is logged in.
  • Data: reading and writing database rows without hand-built SQL strings.
  • Safety: escaping output, hashing passwords, blocking forged form posts.
  • Structure: an agreed place for each kind of file.

Written by hand, each chore is easy to get nearly right, and "nearly" is where security holes live. Laravel is a PHP framework that ships tested answers for all of them. Here is a whole route in Laravel:

Route::get('/books', function () {
    return view('books.index', ['books' => Book::all()]);
});

One line picks the URL, one line fetches every book, and the view escapes the titles before they reach the browser. In plain PHP that same page would mean parsing the URL yourself, opening a database connection, looping over results and escaping each value by hand.

A framework also gives you conventions. Controllers live in app/Http/Controllers, views in resources/views. A developer who has seen one Laravel app can find their way around yours on day one.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.