Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

What is Laravel

Laravel is a framework for building web applications in PHP. It handles the routine parts — routing, database access, authentication, templates — and gives the project a clear structure. You are left to write the code that is specific to your site.

What you need

You need PHP 8.2 or newer and Composer — the PHP package manager. Check in the terminal that they are installed:

php -v
composer -V

Creating a project

A project is created with Composer:

composer create-project laravel/laravel blog
cd blog
php artisan serve

The php artisan serve command starts the built-in development server. The site opens at http://localhost:8000.

Project structure

FolderWhat is inside
app/Application code: models, controllers
routes/Routes
resources/views/Page templates
database/Migrations and seeders
public/Entry point and static files
config/Framework settings

The path of a request

Every request follows the same path:

  1. The browser requests an address, for example /posts.
  2. Laravel finds the route for that address.
  3. The route calls a controller method.
  4. The controller gets data from a model and passes it to a template.
  5. The finished HTML page goes back to the browser.

Each step has its own lesson in this course.

Settings

Settings that differ between your computer and the server live in the .env file in the project root: the site name, debug mode, database access.

APP_NAME=Blog
APP_DEBUG=true

Artisan

artisan is Laravel's command-line helper. It creates files, runs migrations and clears the cache:

php artisan list
php artisan make:controller PostController

The first command lists every command, the second creates a controller.

Common mistake

The .env file holds passwords and keys, so it must not be added to Git — it is already listed in .gitignore. On the server this file is created separately. Be sure to set APP_DEBUG=false there: in debug mode the error page shows visitors the project's code and settings.

Thanks for reading!

Donate to the site — we work hard for you.