-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from BadJacky/feature/add-enum-cast-support
feature: Add enum support for column casting
- Loading branch information
Showing
6 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
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
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Datasets; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Tests\Datasets\Enums\ArticleStatusEnum; | ||
use WendellAdriel\Lift\Attributes\Cast; | ||
use WendellAdriel\Lift\Attributes\PrimaryKey; | ||
use WendellAdriel\Lift\Attributes\Rules; | ||
use WendellAdriel\Lift\Lift; | ||
|
||
class Article extends Model | ||
{ | ||
use Lift; | ||
|
||
#[PrimaryKey] | ||
public int $id; | ||
|
||
#[Cast(ArticleStatusEnum::class)] | ||
#[Rules(['required', 'string', 'in:draft.published,archived'], ['required' => 'The book name cannot be empty', 'in' => 'The status must be draft, published or archived'])] | ||
public ArticleStatusEnum $status; | ||
|
||
protected $fillable = [ | ||
'status', | ||
]; | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Datasets\Enums; | ||
|
||
enum ArticleStatusEnum: string | ||
{ | ||
case DRAFT = 'draft'; | ||
case PUBLISHED = 'published'; | ||
case ARCHIVED = 'archived'; | ||
} |
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