Skip to content

Commit 2c0101d

Browse files
Document Feature::useMorphMap() (laravel#8867)
* Document Feature::useMorphMap() * Fix link * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent a9f1f52 commit 2c0101d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pennant.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- [Default Scope](#default-scope)
1717
- [Nullable Scope](#nullable-scope)
1818
- [Identifying Scope](#identifying-scope)
19+
- [Serializing Scope](#serializing-scope)
1920
- [Rich Feature Values](#rich-feature-values)
2021
- [Retrieving Multiple Features](#retrieving-multiple-features)
2122
- [Eager Loading](#eager-loading)
@@ -535,6 +536,25 @@ class User extends Model implements FeatureScopeable
535536
}
536537
```
537538

539+
<a name="serializing-scope"></a>
540+
### Serializing Scope
541+
542+
By default, Pennant will use a fully qualified class name when storing a feature associated with an Eloquent model. If you are already using an [Eloquent morph map](/docs/{{version}}/eloquent-relationships#custom-polymorphic-types), you may choose to have Pennant also use the morph map to decouple the stored feature from your application structure.
543+
544+
To achieve this, after defining your Eloquent morph map in a service provider, you may invoke the `Feature` facade's `useMorphMap` method:
545+
546+
```php
547+
use Illuminate\Database\Eloquent\Relations\Relation;
548+
use Laravel\Pennant\Feature;
549+
550+
Relation::enforceMorphMap([
551+
'post' => 'App\Models\Post',
552+
'video' => 'App\Models\Video',
553+
]);
554+
555+
Feature::useMorphMap();
556+
```
557+
538558
<a name="rich-feature-values"></a>
539559
## Rich Feature Values
540560

0 commit comments

Comments
 (0)