Francis Landford.
← Laravel Fundamentals
code

Introduction to Laravel & Routing

Laravel is a PHP web application framework built around expressive, readable syntax and a set of conventions that handle the repetitive parts of building a web app — routing, database access, templating, authentication — so you can focus on the logic that's actually specific to your project.

Every request into a Laravel application starts with a route. Routes live in routes/web.php for pages a browser visits directly, and routes/api.php (when present) for JSON APIs. The simplest route just matches a URL to a closure:

Route::get('/', function () {
    return view('welcome');
});

Most real routes point to a controller method instead of an inline closure, which keeps routes/web.php readable as an app grows:

Route::get('/projects', [ProjectController::class, 'index']);

Routes can capture segments of the URL as parameters:

Route::get('/projects/{project}', [ProjectController::class, 'show']);

That {project} segment gets passed into the controller method as an argument, and — thanks to route model binding — Laravel will automatically look up the matching Eloquent model for you if you type-hint it.

Finally, it's good practice to name your routes with ->name('projects.show') so you can reference them elsewhere in your app (in Blade templates, redirects, and so on) without hardcoding the URL. If the URL changes later, every reference to the named route keeps working.