Skip to content

Common Naming Conventions

Keep in mind that you SHOULD use these conventions (so it’s a RECOMMENDATION), but you can ignore them in some cases.

Don’t use shortened names

Exceptions are only well-known and typical ones

  • id (identification)
  • i (iterator in loops)

Acronyms

Treat acronyms as regular words (vote). Examples:

  • HttpServerError
  • UrlFactory
  • $url

Reasons:

  • capital letter after acronym will not mislead (bad example: HTTPService [HTTP or HTTPS?])
  • well-known acronyms are still readable, while not well-known acronyms should not be used at all
  • a simple rule that the same for camelCase and snake_case and kebab-case

File naming

Based on CSS naming conventions we can use naming conventions for our files:

  • use -- (double dash) to designate that this file is modification of some original file (for example, A/B test version of original Blade template or thumbnail of the original image)
  • use __ (double underscore) to designate that this file is has parent file (for example, partial for a Blade template).

Why this solution?

  • Consistent file-naming
  • The same rules as for CSS styles

Blade

text
├─ ./resources/views/pages/events/
   ├─ show.blade.php
   ├─ show--a.blade.php
   ├─ show--b.blade.php
   ├─ show__announcement.blade.php
   ├─ show__description.blade.php
   └─ show__overview.blade.php

In some cases, you may have a lot of partials, and it’s better to move them to a new subdirectory:

text
├─ ./resources/views/pages/events/
   ├─ show__/
   │  ├─ announcement.blade.php
   │  ├─ description.blade.php
   │  ├─ overview.blade.php
   ├─ show--a.blade.php
   └─ show--b.blade.php

Do you have a partial that can be used by different Blade templates? — If it’s not a Blade component like card, panel, widget (see resources/views/components) , you can name using leading double underscore:

text
├─ __successEnrollmentModal.blade.php

Resources

text
├─ s3://images/courses/
   ├─ course_cover_18.jpg
   ├─ course_cover_18.webp
   ├─ course_cover_18.avif
   ├─ course_cover_18--small.jpg
   ├─ course_cover_18--medium.jpg
   ├─ course_cover_18--big.jpg
   └─ course_cover_18--retina_big.jpg

Interfaces and Traits

  • interfaces: {*able}. Examples: Countable, iterable, Traversable, Serializable, JsonSerializable, Throwable,
  • traits, concerns and mixins: {Has*} or {*Has*}. Examples: HasRelationships, HasBadges, MemberHasBadges

Materials