Skip to content

Commit e377829

Browse files
authored
Add Documentation for Module Owned Flights (#25)
* Add Documentation for Module Owned Flights * updated based on feedback
1 parent 27d68f4 commit e377829

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/developers/addons.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,30 @@ class PirepAcceptedListener {
340340
```
341341

342342
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)
343+
344+
## Module Owned Flights
345+
346+
In phpVMS's Flights Table, if your module needs to generate flights for the user to fly, modules can use the `owner` polymoprhic relationship.
347+
348+
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.
349+
350+
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.
351+
352+
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:
353+
354+
```php
355+
$flight->owner_type = FreeFlightProvider::class;
356+
```
357+
358+
If you do have a model, say a flight is attached to a `Tour` model, can add the ID to the specific model.
359+
360+
```php
361+
// Get a tour
362+
$tour = Tour::find(1);
363+
364+
// Attach it to the flight
365+
$flight->owner_type = Tour::class;
366+
$flight->owner_id = $tour->id;
367+
```
368+
369+
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 commit comments

Comments
 (0)