Getting Started

Laravel Fundamentals
Course 1 ยท Chapter 1 ยท Getting Started

๐ŸŽผ Getting Started

Laravel occupies roughly the same "batteries-included" niche as Django โ€” a full ORM, templating engine, routing, and CLI tooling all included from the first command โ€” but built on PHP with its own ecosystem and conventions. This chapter gets a project running and maps Laravel's structure onto what you already know from Django.

Composer, Not Just PHP

Where a plain PHP script needs nothing more than a web server, Laravel is installed and managed through Composer, PHP's dependency manager โ€” the same role pip plays for Django:

composer create-project laravel/laravel example-app
cd example-app
php artisan serve
# INFO  Server running on [http://127.0.0.1:8000].

Django's startproject vs Laravel's create-project

Django
pip install django
django-admin startproject mysite
cd mysite
python manage.py runserver
Laravel
composer create-project laravel/laravel example-app
cd example-app
php artisan serve

๐Ÿ“ Project Structure

Laravel's folder layout maps closely onto Django's app structure, even though the names differ:

example-app/
โ”œโ”€โ”€ artisan                 # the CLI entry point โ€” Laravel's manage.py
โ”œโ”€โ”€ .env                    # environment config (APP_KEY, DB credentials, ...)
โ”œโ”€โ”€ routes/
โ”‚   โ””โ”€โ”€ web.php             # URL routing table โ€” Laravel's urls.py
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ Http/
โ”‚   โ”‚   โ””โ”€โ”€ Controllers/    # request-handling logic โ€” Laravel's views.py
โ”‚   โ””โ”€โ”€ Models/              # Eloquent models โ€” Laravel's models.py
โ”œโ”€โ”€ resources/
โ”‚   โ””โ”€โ”€ views/               # Blade templates โ€” Laravel's templates/ directory
โ”œโ”€โ”€ database/
โ”‚   โ””โ”€โ”€ migrations/          # schema change history โ€” same concept as Django's migrations/
โ””โ”€โ”€ config/                  # split-by-topic settings โ€” Laravel's version of settings.py

One Project, Not Project + Apps

Laravel doesn't split "project" from "app" the way Django does โ€” everything lives under one app/ directory, organized by role (Controllers, Models) rather than by feature area.

config/ Instead of One settings.py

Configuration is split across multiple files by topic (config/database.php, config/app.php, ...) rather than one monolithic settings file โ€” each reads its actual values from .env.

Artisan: Laravel's manage.py

Every Laravel-specific command runs through artisan โ€” migrations, code generation, the dev server, all in one place:

Common Commands, Side by Side

Django (manage.py)
python manage.py runserver
python manage.py migrate
python manage.py startapp blog
python manage.py shell
Laravel (artisan)
php artisan serve
php artisan migrate
php artisan make:controller BlogController
php artisan tinker

php artisan make:*

A whole family of code-generation commands โ€” make:controller, make:model, make:migration โ€” scaffolding boilerplate the way Django's startapp does, just at a finer grain.

php artisan tinker

An interactive REPL with the full application already loaded โ€” directly equivalent to Django's manage.py shell.

The .env File

Laravel bakes environment-based configuration in from the very first command โ€” no separate setup step needed the way Django's Course 2 Deployment chapter had to introduce it:

# .env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:GENERATED_ON_INSTALL
APP_DEBUG=true

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=example_app
DB_USERNAME=root
DB_PASSWORD=

APP_KEY is generated automatically as part of create-project โ€” it's used to encrypt sessions and other sensitive data, and Laravel refuses to run correctly without one (see this chapter's gotcha).

๐Ÿ’ป Coding Challenges

Challenge 1: Create Your First Project

Run composer create-project laravel/laravel library, then start the dev server and confirm the welcome page loads. List the top-level folders it generated and, in one sentence each, what each one is for.

Goal: Get comfortable with the project structure before writing any actual code.

โ†’ Solution

Challenge 2: Explore Artisan

Run php artisan list and pick three commands you haven't used yet. For each, write one sentence describing what it does and when you'd reach for it.

Goal: Build familiarity with Artisan as the single entry point for nearly every Laravel task โ€” the same habit Django's Course 1 built around manage.py help.

โ†’ Solution

Challenge 3: Inspect the .env File

Open a newly created project's .env file and identify: the database connection settings, the debug flag, and the app key. Explain in one sentence what would break if APP_KEY were left empty.

Goal: Practice reading environment-based configuration before it becomes relevant to real settings decisions later in the course.

โ†’ Solution

โš ๏ธ Gotcha: A Missing APP_KEY

composer create-project generates APP_KEY automatically โ€” but if a project is ever cloned from a repository where .env wasn't committed (correctly โ€” .env should never be committed, same as any language's secrets file), the new copy has no key at all. Running the app in that state produces a very literal RuntimeException: No application encryption key has been specified the moment anything tries to use sessions or encrypted data. The fix is php artisan key:generate, which creates a fresh key and writes it into .env โ€” a one-time step worth knowing about the first time it happens, since the error message doesn't obviously point at ".env is missing a value."

๐ŸŽฏ What's Next

With a project running, the next chapter covers how a request finds its way to your code: Routing โ€” routes/web.php, Route::get(), route parameters, and how Laravel's routing compares to Django's urls.py.