-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1169cbb
commit 8b312f1
Showing
3 changed files
with
119 additions
and
11 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
database/migrations/2025_02_23_000001_add_active_column_to_features_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
use Laravel\Pennant\Migrations\PennantMigration; | ||
|
||
return new class extends PennantMigration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('features', function (Blueprint $table) { | ||
$table->boolean('active')->after('value')->nullable(); | ||
$table->text('value')->nullable()->change(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('features', function (Blueprint $table) { | ||
$table->dropColumn('active'); | ||
$table->text('value')->change(); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Laravel\Pennant; | ||
|
||
use Illuminate\Contracts\Support\Arrayable; | ||
use Illuminate\Support\Arr; | ||
|
||
/** @phpstan-consistent-constructor */ | ||
class FeatureValues implements Arrayable | ||
{ | ||
/** | ||
* Whether the Feature is active | ||
* | ||
* @var bool | ||
*/ | ||
protected bool $active; | ||
|
||
/** | ||
* The Feature's value | ||
* | ||
* @var mixed | ||
*/ | ||
protected $value; | ||
|
||
/** | ||
* Create a new Feature Values instance | ||
* | ||
* @param array $values | ||
*/ | ||
public function __construct( | ||
protected array $values, | ||
) { | ||
|
||
$this->value = $this->values['value'] ?? null; | ||
|
||
$this->active = $this->value ? true : false; | ||
|
||
$this->values['active'] = $this->active; | ||
} | ||
|
||
/** | ||
* Make a FeatureValues instance | ||
* | ||
* @param array $values | ||
* @return static | ||
*/ | ||
public static function make(array $values): static | ||
{ | ||
return new static($values); | ||
} | ||
|
||
/** | ||
* Get the values for the instance. | ||
* | ||
* @return array | ||
*/ | ||
public function values(): array | ||
{ | ||
return $this->active ? $this->values : Arr::except($this->values, 'value'); | ||
} | ||
|
||
/** | ||
* Get the instance as an array. | ||
* | ||
* @return array | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return $this->values(); | ||
} | ||
} |