File tree Expand file tree Collapse file tree 8 files changed +16
-28
lines changed
workbench/database/entities/views Expand file tree Collapse file tree 8 files changed +16
-28
lines changed Original file line number Diff line number Diff line change 66
77use Illuminate \Database \Connection ;
88use Illuminate \Database \Query \Builder ;
9+ use Illuminate \Support \Str ;
910use Stringable ;
1011
1112abstract class SqlEntity implements Stringable
1213{
13- /** The entity name. */
14- abstract public function name (): string ;
15-
1614 /** The entity definition. */
1715 abstract public function definition (): Builder |string ;
1816
17+ /** The entity name. */
18+ public function name (): string
19+ {
20+ return Str::snake (class_basename ($ this ));
21+ }
22+
1923 /** The entity connection name. */
2024 public function connectionName (): ?string
2125 {
Original file line number Diff line number Diff line change 3232
3333describe ('get ' , function () {
3434 it ('returns the entity by name ' , function () {
35- $ entity = test ()->manager ->get ('users_view ' );
35+ $ entity = test ()->manager ->get ('user_view ' );
3636
3737 expect ($ entity )->toBeInstanceOf (UserView::class);
3838 });
3939
4040 it ('returns the entity by name and connection ' , function () {
41- $ entity = test ()->manager ->get ('users_view ' , 'foo ' );
41+ $ entity = test ()->manager ->get ('user_view ' , 'foo ' );
4242
4343 expect ($ entity )->toBeInstanceOf (FooConnectionUserView::class);
4444 });
5858
5959 test ()->manager ->create ($ entity );
6060 })->with ([
61- 'name ' => 'users_view ' ,
61+ 'name ' => 'user_view ' ,
6262 'class ' => UserView::class,
6363 'entity ' => new UserView (),
6464 ]);
8585
8686 test ()->manager ->drop ($ entity );
8787 })->with ([
88- 'name ' => 'users_view ' ,
88+ 'name ' => 'user_view ' ,
8989 'class ' => UserView::class,
9090 'entity ' => new UserView (),
9191 ]);
Original file line number Diff line number Diff line change @@ -27,11 +27,6 @@ class Foo extends Model
2727
2828class FooEntity extends SqlEntity
2929{
30- public function name (): string
31- {
32- return 'foo_entity ' ;
33- }
34-
3530 public function definition (): Builder |string
3631 {
3732 return Foo::query ()
Original file line number Diff line number Diff line change @@ -41,11 +41,6 @@ public function compileViewDrop(View $view): string
4141
4242class UnknownSqlEntity extends SqlEntity
4343{
44- public function name (): string
45- {
46- return 'unknown_entity ' ;
47- }
48-
4944 public function definition (): Builder |string
5045 {
5146 return '' ;
Original file line number Diff line number Diff line change 1616 $ sql = test ()->grammar ->compileCreate (new UserView ());
1717
1818 expect ($ sql )->toBe (<<<'SQL'
19- CREATE OR REPLACE VIEW users_view AS
19+ CREATE OR REPLACE VIEW user_view AS
2020 SELECT id, name FROM users
2121 SQL);
2222});
2525 $ sql = test ()->grammar ->compileDrop (new UserView ());
2626
2727 expect ($ sql )->toBe (<<<'SQL'
28- DROP VIEW IF EXISTS users_view CASCADE
28+ DROP VIEW IF EXISTS user_view CASCADE
2929 SQL);
3030});
Original file line number Diff line number Diff line change 1616 $ sql = test ()->grammar ->compileCreate (new UserView ());
1717
1818 expect ($ sql )->toBe (<<<'SQL'
19- CREATE VIEW users_view AS
19+ CREATE VIEW user_view AS
2020 SELECT id, name FROM users
2121 SQL);
2222});
2525 $ sql = test ()->grammar ->compileDrop (new UserView ());
2626
2727 expect ($ sql )->toBe (<<<'SQL'
28- DROP VIEW IF EXISTS users_view
28+ DROP VIEW IF EXISTS user_view
2929 SQL);
3030});
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ class FooConnectionUserView extends View
1212 #[Override]
1313 public function name (): string
1414 {
15- return 'users_view ' ;
15+ return 'user_view ' ;
1616 }
1717
1818 #[Override]
Original file line number Diff line number Diff line change @@ -14,12 +14,6 @@ class UserView extends View
1414
1515 public bool $ shouldDrop = true ;
1616
17- #[Override]
18- public function name (): string
19- {
20- return 'users_view ' ;
21- }
22-
2317 #[Override]
2418 public function definition (): string
2519 {
You can’t perform that action at this time.
0 commit comments