File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ class="{{ $inlineEntryClass }}"
2121 @else
2222 @if ($isStatusEnum () )
2323 <x-forms::status :framework =" $framework" :color =" $value->getColor()" :label =" $getEnumLabel()" />
24+ @elseif ($isNativeEnum () )
25+ {{ $getEnumLabel () } }
2426 @elseif ($multiline )
2527 {!! nl2br (e ($value ?: trans (' forms::strings.blank' ))) ! !}
2628 @elseif (is_array ($value ) )
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ class="{{ $inlineEntryClass }}"
2121 @else
2222 @if ($isStatusEnum () )
2323 <x-forms::status :framework =" $framework" :color =" $value->getColor()" :label =" $getEnumLabel()" />
24+ @elseif ($isNativeEnum () )
25+ {{ $getEnumLabel () } }
2426 @elseif ($multiline )
2527 {!! nl2br (e ($value ?: trans (' forms::strings.blank' ))) ! !}
2628 @elseif (is_array ($value ) )
Original file line number Diff line number Diff line change @@ -17,6 +17,11 @@ public function getEnumLabel(): string
1717 return '' ;
1818 }
1919
20+ public function isNativeEnum (): bool
21+ {
22+ return $ this ->value instanceof BackedEnum && method_exists ($ this ->value , 'getLabel ' );
23+ }
24+
2025 public function isStatusEnum (): bool
2126 {
2227 return $ this ->value instanceof BackedEnum && method_exists ($ this ->value , 'getColor ' );
Original file line number Diff line number Diff line change 66
77class TableCellTest extends TestCase
88{
9+ public function test_it_can_render_enum_table_cell_entries_for_bootstrap_5 ()
10+ {
11+ $ this ->setFrameworkBootstrap5 ();
12+ $ this ->registerTestRoute ('table-cell-enum ' );
13+
14+ $ this ->visit ('/table-cell-enum ' )
15+ ->seeElement ('td ' )
16+ ->within ('td ' , function () {
17+ $ this ->seeText ('Report Article ' );
18+ });
19+
20+ }
21+
22+ public function test_it_can_render_enum_table_cell_entries_for_material_admin_26 ()
23+ {
24+ $ this ->setFrameworkMaterialAdmin26 ();
25+ $ this ->registerTestRoute ('table-cell-enum ' );
26+
27+ $ this ->visit ('/table-cell-enum ' )
28+ ->seeElement ('td ' )
29+ ->within ('td ' , function () {
30+ $ this ->seeText ('Report Article ' );
31+ });
32+
33+ }
34+
935 public function test_it_can_render_status_table_cell_entries_for_bootstrap_5 ()
1036 {
1137 $ this ->setFrameworkBootstrap5 ();
Original file line number Diff line number Diff line change 66
77class TextEntryTest extends TestCase
88{
9+ public function test_it_can_render_enum_entries_for_bootstrap_5 ()
10+ {
11+ $ this ->setFrameworkBootstrap5 ();
12+ $ this ->registerTestRoute ('text-entry-enum ' );
13+
14+ $ this ->visit ('/text-entry-enum ' )
15+ ->seeElement ('dl ' )
16+ ->within ('dl ' , function () {
17+ $ this ->seeElement ('dt ' )
18+ ->seeInElement ('dt ' , 'Type ' )
19+ ->seeElement ('dd ' )
20+ ->within ('dd ' , function () {
21+ $ this ->seeText ('Report Article ' );
22+ });
23+ });
24+
25+ }
26+
27+ public function test_it_can_render_enum_entries_for_material_admin_26 ()
28+ {
29+ $ this ->setFrameworkMaterialAdmin26 ();
30+ $ this ->registerTestRoute ('text-entry-enum ' );
31+
32+ $ this ->visit ('/text-entry-enum ' )
33+ ->seeElement ('dl ' )
34+ ->within ('dl ' , function () {
35+ $ this ->seeElement ('dt ' )
36+ ->seeInElement ('dt ' , 'Type ' )
37+ ->seeElement ('dd ' )
38+ ->within ('dd ' , function () {
39+ $ this ->seeText ('Report Article ' );
40+ });
41+ });
42+
43+ }
44+
945 public function test_it_can_render_status_entries_for_bootstrap_5 ()
1046 {
1147 $ this ->setFrameworkBootstrap5 ();
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Javaabu \Forms \Tests \TestSupport \Enums ;
4+
5+ enum ArticleTypes: string
6+ {
7+ case Report = 'report ' ;
8+ case Image = 'image ' ;
9+
10+ public function getLabel (): string
11+ {
12+ return match ($ this ) {
13+ self ::Report => 'Report Article ' ,
14+ self ::Image => 'Image Article '
15+ };
16+ }
17+ }
Original file line number Diff line number Diff line change 66use Illuminate \Database \Eloquent \Factories \HasFactory ;
77use Illuminate \Database \Eloquent \Model ;
88use Javaabu \Forms \Tests \TestSupport \Enums \ArticleStatuses ;
9+ use Javaabu \Forms \Tests \TestSupport \Enums \ArticleTypes ;
910use Spatie \MediaLibrary \HasMedia ;
1011use Spatie \MediaLibrary \InteractsWithMedia ;
1112use Spatie \MediaLibrary \MediaCollections \Models \Media ;
@@ -19,10 +20,12 @@ class Article extends Model implements HasMedia
1920 'status ' ,
2021 'title ' ,
2122 'content ' ,
23+ 'type ' ,
2224 ];
2325
2426 protected $ casts = [
2527 'status ' => ArticleStatuses::class,
28+ 'type ' => ArticleTypes::class,
2629 ];
2730
2831 protected $ attributes = [
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ public function up()
1717 $ table ->string ('title ' );
1818 $ table ->text ('content ' )->nullable ();
1919 $ table ->string ('status ' )->index ();
20+ $ table ->string ('type ' )->nullable ();
2021 $ table ->timestamps ();
2122 });
2223 }
Original file line number Diff line number Diff line change 1+ @php
2+ $article = new \Javaabu\Forms\Tests\TestSupport\Models\ Article ();
3+ $article -> type = \Javaabu \Forms \Tests \TestSupport \Enums \ArticleTypes:: Report ;
4+ @endphp
5+
6+ @model ($article )
7+ <table >
8+ <x-forms::table .cell name =" type" />
9+ </table >
10+ @endmodel
Original file line number Diff line number Diff line change 1+ @php
2+ $article = new \Javaabu\Forms\Tests\TestSupport\Models\ Article ();
3+ $article -> type = \Javaabu \Forms \Tests \TestSupport \Enums \ArticleTypes:: Report ;
4+ @endphp
5+
6+ @model ($article )
7+ <x-forms::text-entry name =" type" />
8+ @endmodel
You can’t perform that action at this time.
0 commit comments