header('Location: /');,
$_GET,
$_POST,
setcookie();,
$_COOKIE,
session_start();,
http_response_code();,
move_uploaded_file();,
__DIR__,
$_ENV,
…
… might feel like handling black boxes
But after a while, you will learn to dig into / intervene in them.
—
Many of the functional Laravel code is located somewhere in thevendor folder,
which of course you should not modify (not on git). Often, the code is organized into traits of which you can override the methods in your own project.
trait keyword e.g. trait Example {use Example; inside the class->) with property overloading
__set() is called when writing to non-existing properties with ->__get() is called when reading non-existing properties with ->Baz within a namespace: start with namespace Ikdoeict\Demo;Baz: refer to other classes of the same namespace: just by their base nameuse Ikdoeict\Base\Model; and just use Model after thatImportant remark
\\wsl$ in Explorer and CLI through your distro
$ composer create-project laravel/laravel <path> ^12.0
<path> is the actual directory where you want to install Laravel, e.g. . = current directory^12.0 tag is optional - semantic versioning: everything within 12.*.* range is backward compatiblecomposer create-project is the equivalent of git clone + composer install.
So:
.htaccess file and a rather complex composer.json file. vendor folder and composer.lock is generated.laravel new projectname, is the officially documented way to install Laravel through an interactive menu. You cannot specify the Laravel version number!
public/ — Public files
index.php — Request Entry Point - please don't touch itcss/ & js/ & img/ & files/ & ….htaccess (or alike), favicon.ico, robots.txtroutes/ — Routes
web.php — Your web routesapi.php — Your (stateless) API routes (requires php artisan install:api)console.php — Your Artisan console routeschannels.php — Your channels for event broadcasting (websockets; requires php artisan install:broadcasting)app/ — PSR-4 classes of your application — 3…13 subfolders e.g.
Console/ — Your Artisan commandsHttp/ — Your controllers and middlewarebootstrap/ — Bootstrap and autoloading
config/ — Configuration files
database/ — Database migration and seeds
lang/ — Language files (only when you publish them by Artisan)
resources/ — Raw assets (to be compiled) such as templates and localization files
storage/ — All kinds of generated files: logs, transpiled templates, caches, …
tests/ — Automated tests (PHPUnit or Pest)
vendor/ — (as created by Composer)
.env — Environment configuration: see next slides
.env.example — Example environment configuration: see next slides
.gitignore — (already configured)
artisan — supports Artisan CLI
composer.json & composer.lock
How Laravel works
(Laravel docs)
public/index.phpbootstrap/app.php scriptregister and boot on the
service providers defined in bootstrap/providers.php$ php artisan list
$ php artisan help serve
master in the URLs for the most recent Laravel version
Pay attention!
storage/ and bootstrap/cache writable by web server (associated account).env environment file$ php artisan key:generateconfig Folderconfig/app.php — Main settings, locale, timezone, automatically loaded service providers, …
config/database.php — Database connection configurations
config/cache.php, config/session.php, …
config/cors.php) can be generated by php artisan config:publish
'charset' => 'utf8mb4',
config/*.php files
config/app.php: 'key' => env('APP_KEY'),
config/database.php: 'password' => env('DB_PASSWORD', 'Azerty123'),
.env file e.g. APP_KEY=base64:DBHbcyBbq0pBarhWVn0S8bYMqt9IV9EhXhthcyeioKw=
DB_PASSWORD=secret
.env file must/can be used to override settings in the
config files
config/*.php.env.env must be kept out of version control (git → .gitignore)..env README.md: if necessary, put .env's non-sensitive lines into .env.example and suggest to cp .env.example .env in the installation instructionsconfig/database.php
<?php
return [
…
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'sqlite' => [
…
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'db009.my-hosting-company.be'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'events'),
'username' => env('DB_USERNAME', 'production'),
'password' => env('DB_PASSWORD', 'Azerty123'),
'charset' => 'utf8mb4',
…
.env
APP_NAME=Concert Guide
APP_ENV=local
APP_KEY=base64:WB2aLCAIUgFJCZbbg/KIA6M4Hum1bsz/s+o8hxbeW68=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost:8080
...
DB_CONNECTION=sqlite
DB_CONNECTION=sqlite if you agree with the default connection in config/database.php .env
$ php artisan about
$ php artisan config:show database
colored text = with Docker on Windows
git clone <repo-url> inside the WSL2-Linux filesystem/docker-compose.yml /.gitignore
/docker/Dockerfile /docker/php.ini (/docker/dump.sql)
/app
/app empty. /app/public will become the document root of the web container later on
docker-compose up
docker-compose exec -u 1000:1000 php-web bash
$ composer create-project laravel/laravel . ^12.0
$ chmod -R 777 storage bootstrap/cache
.env (APP_*, DB_* and SESSION_DRIVER=file) and config/*.php.env to .env.examplegit add .
git commit -m "Adding initial Laravel project"
git pushgit clone <repo-url> inside the WSL2-Linux filesystemdocker-compose up
docker-compose exec -u 1000:1000 php-web bash
$ composer install
$ cp .env.example .env
$ php artisan key:generate
$ chmod -R 777 storage bootstrap/cache