Skip to content

Commit

Permalink
Add Documentation for Module Owned Flights (#25)
Browse files Browse the repository at this point in the history
* Add Documentation for Module Owned Flights

* updated based on feedback
  • Loading branch information
BossOfGames authored Nov 27, 2024
1 parent 27d68f4 commit e377829
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/developers/addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,30 @@ class PirepAcceptedListener {
```

The methods in the repositories largely mirror the Model methods, but can automatically handle searches, etc. The docs for the repositories [are available here](https://github.com/andersao/l5-repository#prettusrepositorycontractsrepositoryinterface). You can read more about the repository pattern [here](https://bosnadev.com/2015/03/07/using-repository-pattern-in-laravel-5/?utm_source=prettus-l5-repository&utm_medium=readme&utm_campaign=prettus-l5-repository)

## Module Owned Flights

In phpVMS's Flights Table, if your module needs to generate flights for the user to fly, modules can use the `owner` polymoprhic relationship.

When a flight is owned by a module, the flight will not be subject to phpVMS's core automation (e.g. hiding and showing flights). Therefore, you must define your own automation regarding how flights behave and are accessible.

You can use the owner polymorphic relationship in two ways. The first way involves just setting the type. The type is what's checked in the core code to validate the existence of a module owned flight.

In this case, one way to utilize this, especially if you don't have a relationship to a model setup, is to set one of your module's service providers as the class. For example:

```php
$flight->owner_type = FreeFlightProvider::class;
```

If you do have a model, say a flight is attached to a `Tour` model, can add the ID to the specific model.

```php
// Get a tour
$tour = Tour::find(1);

// Attach it to the flight
$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.

0 comments on commit e377829

Please sign in to comment.