Skip to content

Add Module and Table Naming Conventions for 3rd parties #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion docs/developers/addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ Which generates the basic structure in the `/modules` folder. After generating t
All of the examples below will be based on a module named `Sample`. To see the source for the module, [check it out on GitHub](https://github.com/nabeelio/phpvms-module).
:::

:::tip

When naming your module, it is recommended that if your module name runs the risk of being generic, to prefix your module name with a unique identifier. For example, instead of naming your module `Tours`, name it `XXTours` (The XX in the example being the identifier or brand name you choose)

In doing this, you reduce the chance of your module name conflicting directly with another module.

:::

---

## Namespacing
Expand Down Expand Up @@ -166,6 +174,8 @@ if(Auth::check())

# Database Access



## Models
Models are the more basic way to access your database tables. For example, if you have a table called `sample_table`, a model called `SampleTable` would make most sense. While table names generally refer to objects in the plural, a model is named for an item in it's singular form.

Expand Down Expand Up @@ -233,6 +243,17 @@ The `app/Database/migrations` directory has the core migrations and is a good re

!!!! Add new migration files when you have to modify a table, etc, after you've released it into the wild. The migrations that are run are kept track of, so if it's seen that it's already run the file, it won't run it again.

:::warning[Table Name Convention]

When naming tables, table names *should* be prefixed with a short indentifier that is unqiue to your addon or group of addons (e.g. `disposable_`, `ch_`, `sp_`, etc.). For example, instead of naming a table `tours`, name it `ch_tours`. This includes pivot tables. See Laravel documentation on how to override the default conventions for table names, foreign relationships, etc. where required.

Not prefixing your tables could lead to unintended consequences, including but not limited to:

* Conflicting with future phpVMS core features that would use the same table name, thereby making it more difficult to update phpVMS at a later date.
* Conflicting with other addons by other 3rd party modules that don't head this warning.

:::

### Seeding Data

I've added a few extra features, including adding seed data, including adding seeder data. For example, the `Settings` table:
Expand Down Expand Up @@ -366,4 +387,4 @@ $flight->owner_type = Tour::class;
$flight->owner_id = $tour->id;
```

If you have a polymorphic relationship setup on the Tour model, you can use the operators given via Laravel. See the [Polymorphic Relationship docs](https://laravel.com/docs/11.x/eloquent-relationships#polymorphic-relationships) for more info.
If you have a polymorphic relationship setup on the Tour model, you can use the operators given via Laravel. See the [Polymorphic Relationship docs](https://laravel.com/docs/11.x/eloquent-relationships#polymorphic-relationships) for more info.