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
- The
.env
files are not saved by default.- Copy
.env.example
as.env
before running - Error 500 may occur when the
.env
file is missing.
- Copy
- Run with VS Code and the suggested Extensions
- See,
.vscode/extensions.json
for more info.
- See,
- Execute,
composer install
to download the Vendor packages. - Execute,
php artisan migrate
to create the database before runningphp artisan migrate:fresh
- Drop tables and recreatephp artisan migrate:fresh --seed
- Seed table with test data (when project states to do so)
- Launch project,
php artisan serve
- Template Projects
- VS Code Project Template
- Custom Database Naming Convention Template
- CRUD - Basic webpage form with Create, Read, Update, and Delete operations
- Form Validation - Form submission validator with recall of previously entered values
- REST API Login and CRUD operation - Including VS Code tester using REST Client extension
- REST API and CRUD - Slightly more complex implementation of the same thing
- Custom DB Naming Conventions - Column names using PascalCase and not the gross
snake_case
.- Pascal Case - Seeder - DB Factory and Seeder example using your PascalCase columns
- Pascal Case - API - Web API for creating "Customers and Products"
- Pascal Case - Filter Results
- Pascal Case - Include Invoice
- Pascal Case - POST PUT PATCH - Create and Update items
- Pascal Case - Upload Update - Massive upload information to store in DB
- Pascal Case - Unit Testing - How to test your Custom DB Naming Conventions
- Pivot Table - COMING SOON
- Web API Service - COMING SOON - Use services to link both View and API logic.
- Database - Pivot Table
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.)
- Deleting Multiple Records
- Publish API Route File
- File Upload Example
- AJAX Request Example
- JQuery Ajax Loading Spinner Example
- Generate and Read Sitemap XML File Example
- Testing Database with Factory and Seeders
Checkout debugging.md for more information
php artisan migrate --pretend
- Show the migration SQL queries before they're ran
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.)
- Models - Always singular and
PascalCase
- Controllers - Usually singular and ending with the word,
Controller
. i.e.PostController
- Database: Query Builder
- Deleting Multiple Records
- Publish API Route File
- File Upload Example
- AJAX Request Example
- JQuery Ajax Loading Spinner Example
- Generate and Read Sitemap XML File Example
- Testing Database with Factory and Seeders - Blog, Video