Learn how to use Laravel 11 through small example apps
In this edition of the Suess Labs' Learn repository, we'll dive into the Laravel PHP framework for web applications.
Author: Damian Suess Website: suesslabs.com
The following projects dive into the basics and customization of Laravel.
Looking back, I've usually always created custom micro-frameworks with PHP to keep things lean, quick, and target a project's needs. However, there are a few bottlenecks that can come of that. Namingly, rapid prototyping, maintainability, and scalability can quickly pinch points throughout a product's lifecycle. As a consideration, frameworks like Laravel can assist with such things.
By all means, explore and build your frameworks! This will teach you a lot of solid fundamentals, especially the core functionality of PHP.
In the PascalCase sample project the following mottos are applied:
The projects using PascalCase are an example of overriding Laravel's default naming conventions. In reality, most organizations have their own (legacy) conventions. Whether it be
passwd
vs.password
,userName
vs.name
, orrememberToken
instead ofremember_token
.Most samples people provide are a 1-to-1 on the naming, leaning into the Laravel "magic glue".
A framework should be flexible and well-documented to suit the customer's needs. When it's too ridged, copious amounts of scaffolding and code smells will occur.
composer install
cp .env.example .env
php artisan migrate
php artisan key:generate
php artisan serve
Before running a sample project please note the following
.env
files are not saved by default.
.env.example
as .env
before running.env
file is missing..vscode/extensions.json
for more info.composer install
to download the Vendor packages.php artisan migrate
to create the database before running
php artisan migrate:fresh
- Drop tables and recreatephp artisan migrate:fresh --seed
- Seed table with test data (when project states to do so)php artisan serve
snake_case
.
composer create-project laravel/laravel #.#-AppName
composer require --dev friendsofphp/php-cs-fixer
./vendor/bin/php-cs-fixer fix # Reformats EVERYTHING!
# ./vendor/bin/php-cs-fixer fix app # Reformats only /app/ folder
The projects listed here are based on the following examples. The examples in this repository have been modified and improved upon (bug fixes, added functionality, testability, etc.)
Checkout debugging.md for more information
php artisan migrate --pretend
There are many "rules" out there which veer off from one another, however, the following appears to be widely accepted. (Frankly, I often use Xeno Innovations' legacy rules.)
PascalCase
Controller
. i.e. PostController