Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Request–Response Flow and Project Folders  ›  Lesson

app, bootstrap and config

App 12 minapp/ holds your own PHP classes, bootstrap/ builds the application, and config/ holds settings files that read their values from .env.

app, bootstrap and config

Open a fresh Laravel project and you see about a dozen folders. Three of them decide how the app is built and how it behaves: app/ for your classes, bootstrap/ for starting the app, and config/ for settings. Put things in the right one and Laravel finds them without being told.

The rule

app/ is your code, bootstrap/ starts it, config/ tunes it.

app/: your own PHP classes. Everything here uses the App\ namespace, so app/Models/Book.php is App\Models\Book.

  • app/Models/: Eloquent models, such as User and Book
  • app/Http/Controllers/: controllers
  • app/Providers/: service providers, such as AppServiceProvider

More folders, such as app/Jobs or app/Policies, appear when you generate those classes with Artisan.

bootstrap/: building the app.

  • bootstrap/app.php: routing, middleware and exception setup
  • bootstrap/providers.php: the list of service providers to load
  • bootstrap/cache/: files Laravel generates to start faster. Never edit them.

config/: settings, one file per area, such as app.php, database.php, mail.php and session.php. Each file returns an array, and values that change per machine are pulled from .env:

// config/lendly.php
return [
    'loan_days' => env('LOAN_DAYS', 14),
];

Code reads settings with dot notation, file name first:

$days = config('lendly.loan_days'); // 14 unless .env says otherwise

Some config files are hidden in a new app to keep it small. php artisan config:publish copies them in when you need to change one.

The shortcut

Call env() only inside config/. Everywhere else, use config(). In production you run php artisan config:cache, which saves all settings into one file, and after that env() calls outside config files return null.

Adding a loan-length settingStep 1 of 4
  1. Name the value

    LOAN_DAYS=21 goes in .env, because it may differ per environment.

Drills

Answer fast — trust the rule.

quick drill

Where does the Book model normally live?

quick drill

How should a controller read the mail sender's address?

quick drill

Which file lists the service providers Laravel loads?

quick drill

After php artisan config:cache, what does env('LOAN_DAYS') return inside a controller?

Remember

  • app/ is your code, bootstrap/ starts it, config/ tunes it.
  • env() only inside config files; config('file.key') everywhere else.
  • Trap: never edit bootstrap/cache, since Laravel rebuilds it.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhere does it go?

For Lendly, say which folder each of these belongs in and why: a Book model, a LoanController, the list of service providers, and a setting for how many days a loan lasts. Explain how the loan setting should be read from code.