Skip to content

Commit

Permalink
Can now automatically add licenses when checking if there are any ava…
Browse files Browse the repository at this point in the history
…ilable
  • Loading branch information
tylercd100 committed Sep 16, 2017
1 parent b113c43 commit a135f29
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to `laravel-licenser` will be documented in this file.

### 1.1.0
- Can now automatically add licenses when checking if there are any available

### 1.0.2
- Fixed adding or subtracting licenses by 0

Expand Down
9 changes: 7 additions & 2 deletions src/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ function __construct(Model $owner)
* Throws exception if there are not enough licenses available
*
* @param int $quantity
* @param boolean $add
* @return void
*/
public function check($quantity)
public function check($quantity, $add = false)
{
$remaining = $this->remaining();
if ($remaining < $quantity) {
throw new LicenseException($this->message($remaining, $quantity));
if(!$add) {
throw new LicenseException($this->message($remaining, $quantity));
} else {
$this->add($quantity - $remaining);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Traits/HasLicenses.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

trait HasLicenses
{
public function checkLicensesAvailable($class, $quantity)
public function checkLicensesAvailable($class, $quantity, $add = false)
{
$license = $this->getLicenseInstance($class);
$license->check($quantity);
$license->check($quantity, $add);
return $this;
}

Expand Down

0 comments on commit a135f29

Please sign in to comment.