Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #28 from renoki-co/feature/popular-plan
Browse files Browse the repository at this point in the history
[feature] Popular plan marker
  • Loading branch information
rennokki authored May 10, 2021
2 parents bf2d32d + b1b77ea commit 6e603b3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,17 @@ $planData = $plan->getData(); // ['golden' => true]
$featureData = $feature->getData(); // ['digital' => true]
```

### Setting the plan as popular

Some plans are popular among others, and you can simply mark them:

```php
Saas::plan('Gold Plan', 'gold-plan')
->popular();
```

This will add a data field called `popular` that is either `true/false`.

## 🐛 Testing

``` bash
Expand Down
14 changes: 13 additions & 1 deletion src/Concerns/HasData.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,22 @@ public function data(array $data)
return $this;
}

/**
* Set the plan as being popular.
*
* @return self
*/
public function popular()
{
return $this->data(array_merge(
$this->getData(), ['popular' => true]
));
}

/**
* Get the list of all features.
*
* @return \Illuminate\Support\Collection
* @return array
*/
public function getData()
{
Expand Down
5 changes: 3 additions & 2 deletions tests/PlanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public function test_build_plans()
Saas::plan('Active Plan', 'plan')
->price(10, 'USD')
->description('Some plan...')
->data(['somekey' => 'someval']);
->data(['somekey' => 'someval'])
->popular();

Saas::plan('Archived Plan', 'archived-plan')
->price(15, 'USD')
Expand All @@ -25,7 +26,7 @@ public function test_build_plans()

$this->assertEquals('plan', $plan->getId());

$this->assertEquals(['somekey' => 'someval'], $plan->getData());
$this->assertEquals(['somekey' => 'someval', 'popular' => true], $plan->getData());
}

public function test_build_plans_with_features()
Expand Down

0 comments on commit 6e603b3

Please sign in to comment.