@@ -25,7 +25,7 @@ public function build()
2525 {
2626 $ cache = new QuickCache ();
2727 $ cached = $ cache ->get ('fieldsinfo ' );
28- $ this ->template = __DIR__ . DIRECTORY_SEPARATOR .'.. ' . DIRECTORY_SEPARATOR .'Templates ' . DIRECTORY_SEPARATOR .'request ' ;
28+ $ this ->template = __DIR__ . DIRECTORY_SEPARATOR . '.. ' . DIRECTORY_SEPARATOR . 'Templates ' . DIRECTORY_SEPARATOR . 'request ' ;
2929 $ this ->name = $ cached ['name ' ];
3030 $ this ->fields = $ cached ['fields ' ];
3131 $ this ->soft = $ cached ['soft_delete ' ];
@@ -89,7 +89,7 @@ private function buildRules($type)
8989 foreach ($ this ->fields as $ field ) {
9090 // Check if there is no duplication for radio and checkbox
9191 if (!in_array ($ field ->title , $ used )) {
92- if ($ field ->type != 'file ' ) {
92+ if ($ field ->type != 'file ' && $ field -> type != ' relationship ' ) {
9393 if ($ type == 0 || $ field ->type != 'password ' ) {
9494 switch ($ field ->validation ) {
9595 case 'required ' :
@@ -103,7 +103,19 @@ private function buildRules($type)
103103 break ;
104104 }
105105 }
106- } else {
106+ } elseif ($ field ->type == 'relationship ' ) {
107+ switch ($ field ->validation ) {
108+ case 'required ' :
109+ $ rules .= "' " . $ field ->relationship_name . "_ " . $ field ->relationship_field . "' => ' $ field ->validation ', \r\n " ;
110+ break ;
111+ case 'required|unique ' :
112+ $ camelName = Str::camel ($ this ->name );
113+ // Insert table names
114+ $ tableName = strtolower ($ camelName );
115+ $ rules .= "' " . $ field ->relationship_name . "_ " . $ field ->relationship_field . "' => ' $ field ->validation : $ tableName, $ field ->title ,'. " . '$this-> ' . $ this ->request . ", \r\n " ;
116+ break ;
117+ }
118+ } elseif ($ field ->type == 'file ' ) {
107119 switch ($ field ->validation ) {
108120 case 'required ' :
109121 $ rules .= "' $ field ->title ' => 'max: $ field ->size | $ field ->validation ', \r\n " ;
@@ -146,8 +158,10 @@ private function names()
146158 */
147159 private function publish ($ template )
148160 {
149- file_put_contents (app_path ('Http ' . DIRECTORY_SEPARATOR .'Requests ' . DIRECTORY_SEPARATOR .'Create ' . $ this ->fileName ), $ template [0 ]);
150- file_put_contents (app_path ('Http ' . DIRECTORY_SEPARATOR .'Requests ' . DIRECTORY_SEPARATOR .'Update ' . $ this ->fileName ), $ template [1 ]);
161+ file_put_contents (app_path ('Http ' . DIRECTORY_SEPARATOR . 'Requests ' . DIRECTORY_SEPARATOR . 'Create ' . $ this ->fileName ),
162+ $ template [0 ]);
163+ file_put_contents (app_path ('Http ' . DIRECTORY_SEPARATOR . 'Requests ' . DIRECTORY_SEPARATOR . 'Update ' . $ this ->fileName ),
164+ $ template [1 ]);
151165 }
152166
153167}
0 commit comments