Consistent coding standards are the difference between a codebase you enjoy working in and one you dread. They matter even more when you're working remotely with international clients or collaborating across time zones — your code needs to speak clearly without you being present to explain it.

PSR Standards — The Foundation

PHP-FIG (Framework Interop Group) PSR standards are the universal baseline for PHP code. Laravel follows them, and so should you.

PSR-1: Basic Coding Standard

  • Use only opening tags <?php
  • Files must use UTF-8 without BOM
  • Class names in PascalCase
  • Method names in camelCase
  • Constants in UPPER_CASE
php
// Good
class UserService
{
    public function getUserById(int $id): ?User
    {
        return User::find($id);
    }
}

// Bad
class user_service
{
    public function get_user_by_id($id)
    {
        return User::find($id);
    }
}

PSR-12: Extended Coding Style

  • 4 spaces for indentation — never tabs
  • Lines should be 120 characters or fewer
  • One blank line between methods
  • Type declarations on all method signatures
php
// Good
if ($condition) {
    $result = processData($data);
    return $result;
}

// Bad
if($condition){
$result=processData($data);return $result;
}

Laravel-Specific Conventions

Naming Conventions

php
// Controllers — PascalCase, singular, "Controller" suffix
class UserController extends Controller {}

// Models — singular PascalCase
class BlogPost extends Model {}

// Variables — camelCase
$userData = [];
$isActive = true;

// Database tables — plural snake_case
// users, blog_posts, user_profiles

// Routes — kebab-case
Route::get('/user-profiles', ...);
Route::get('/blog-posts/{post}', ...);

Always Type-Hint Your Methods

php
// Good — clear, self-documenting, IDE-friendly
public function createUser(array $data): User
{
    return User::create($data);
}

// Bad — no one knows what goes in or comes out
public function createUser($data)
{
    return User::create($data);
}

Document Non-Obvious Methods

php
/**
 * Calculate pro-rated salary for partial month employment.
 *
 * @param User $user
 * @param Carbon $startDate  First day of employment in the period
 * @param int $workingDays   Total working days in the month
 * @return float             Gross salary amount in BDT
 */
public function calculateProratedSalary(User $user, Carbon $startDate, int $workingDays): float
{
    // ...
}

Automated Quality Tools

PHP CS Fixer — Auto-format your code

bash
composer require --dev friendsofphp/php-cs-fixer

# Fix all files in app/
./vendor/bin/php-cs-fixer fix app/

PHP CodeSniffer — Check standards compliance

bash
composer require --dev squizlabs/php_codesniffer

# Check
./vendor/bin/phpcs --standard=PSR12 app/

# Auto-fix where possible
./vendor/bin/phpcbf --standard=PSR12 app/

Team Practices

  • Add a .editorconfig to your repo — enforces consistent indentation and line endings across all editors automatically
  • Set up a Git pre-commit hook to run PHP CS Fixer before every commit
  • Write code and comments in English — it's universal and expected by international clients and open source contributors
  • Run code reviews on every PR — the act of explaining your code to a colleague is itself a quality filter

Conclusion

Start with PSR-12 and Laravel's own conventions — they cover 90% of the decisions you'll face. Add PHP CS Fixer to your workflow to automate formatting entirely so you never have to think about it again. The goal isn't perfect code, it's consistent code that any developer can read and modify confidently.

Author bio block:

About the Author

Kamruzzaman Polash — Software Engineer specialising in Laravel, REST APIs, and scalable backend systems. 10+ projects delivered for clients worldwide.

Portfolio Contact GitHub LinkedIn


11. Images & Media Inventory

There are no content <img> elements anywhere in the site (no project screenshots, no blog images, no headshot, no logos). The only image assets in the repo are branding files:

File Purpose Referenced from
/favicon.svg Apple touch icon + SVG favicon every page
/favicon-32x32.png PNG favicon 32×32 every page
/favicon-16x16.png PNG favicon 16×16 every page
/og-image.svg Open Graph social image homepage, blog index, 15 blog posts
/twitter-image.svg Twitter card image homepage, blog index, 15 blog posts

Notes for the rebuild:

  • No image alt attributes exist because there are no <img> tags. If the new design adds images, alt text must be created from scratch.
  • The OG/Twitter images are SVG, which Facebook, X/Twitter, LinkedIn, and Slack do not reliably render (they expect PNG/JPG, 1200×630). Replace with raster images.
  • favicon.ico is not present (only svg/png).


End of content export.

Work with me

Need help with your Laravel architecture?

I build clean, maintainable Laravel backends for SaaS products — REST APIs, queue systems and production patterns like the one in this article.