@@ -39,6 +39,7 @@ class Form implements Renderable
3939 use HasFormAttributes;
4040 use HandleCascadeFields;
4141 use ShouldSnakeAttributes;
42+
4243 /**
4344 * Remove flag in `has many` form.
4445 */
@@ -183,8 +184,12 @@ public function pushField(Field $field): self
183184 /**
184185 * @return Model
185186 */
186- public function model (): Model
187+ public function model (): ? Model
187188 {
189+ if ($ this ->model instanceof Actions \Interactor \Form) {
190+ return $ this ->model ->getRow ();
191+ }
192+
188193 return $ this ->model ;
189194 }
190195
@@ -224,9 +229,9 @@ public function edit($id): self
224229 /**
225230 * Use tab to split form.
226231 *
227- * @param string $title
232+ * @param string $title
228233 * @param Closure $content
229- * @param bool $active
234+ * @param bool $active
230235 *
231236 * @return $this
232237 */
@@ -300,12 +305,12 @@ public function destroy($id)
300305 }
301306
302307 $ response = [
303- 'status ' => true ,
308+ 'status ' => true ,
304309 'message ' => trans ('admin.delete_succeeded ' ),
305310 ];
306311 } catch (\Exception $ exception ) {
307312 $ response = [
308- 'status ' => false ,
313+ 'status ' => false ,
309314 'message ' => $ exception ->getMessage () ?: trans ('admin.delete_failed ' ),
310315 ];
311316 }
@@ -317,7 +322,7 @@ public function destroy($id)
317322 * Remove files in record.
318323 *
319324 * @param Model $model
320- * @param bool $forceDelete
325+ * @param bool $forceDelete
321326 */
322327 protected function deleteFiles (Model $ model , $ forceDelete = false )
323328 {
@@ -401,9 +406,9 @@ protected function responseValidationError(MessageBag $message)
401406 {
402407 if (\request ()->ajax () && !\request ()->pjax ()) {
403408 return response ()->json ([
404- 'status ' => false ,
409+ 'status ' => false ,
405410 'validation ' => $ message ,
406- 'message ' => $ message ->first (),
411+ 'message ' => $ message ->first (),
407412 ]);
408413 }
409414
@@ -424,7 +429,7 @@ protected function ajaxResponse($message)
424429 // ajax but not pjax
425430 if ($ request ->ajax () && !$ request ->pjax ()) {
426431 return response ()->json ([
427- 'status ' => true ,
432+ 'status ' => true ,
428433 'message ' => $ message ,
429434 'display ' => $ this ->applayFieldDisplay (),
430435 ]);
@@ -517,7 +522,7 @@ protected function getRelationInputs($inputs = []): array
517522
518523 foreach ($ inputs as $ column => $ value ) {
519524 if ((method_exists ($ this ->model , $ column )
520- || method_exists ($ this ->model , $ column = Str::camel ($ column )))
525+ || method_exists ($ this ->model , $ column = Str::camel ($ column )))
521526 && !method_exists (Model::class, $ column )
522527 ) {
523528 $ relation = call_user_func ([$ this ->model , $ column ]);
@@ -534,7 +539,7 @@ protected function getRelationInputs($inputs = []): array
534539 /**
535540 * Handle update.
536541 *
537- * @param int $id
542+ * @param int $id
538543 * @param null $data
539544 *
540545 * @return bool|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|mixed|null|Response
@@ -605,7 +610,7 @@ public function update($id, $data = null)
605610 protected function redirectAfterStore ()
606611 {
607612 $ resourcesPath = $ this ->resource (0 );
608- $ key = $ this ->model ->getKey ();
613+ $ key = $ this ->model ->getKey ();
609614
610615 return $ this ->redirectAfterSaving ($ resourcesPath , $ key );
611616 }
@@ -636,13 +641,13 @@ protected function redirectAfterSaving($resourcesPath, $key)
636641 {
637642 if (request ('after-save ' ) == 'continue_editing ' ) {
638643 // continue editing
639- $ url = rtrim ($ resourcesPath , '/ ' ). "/ {$ key }/edit " ;
644+ $ url = rtrim ($ resourcesPath , '/ ' ) . "/ {$ key }/edit " ;
640645 } elseif (request ('after-save ' ) == 'continue_creating ' ) {
641646 // continue creating
642- $ url = rtrim ($ resourcesPath , '/ ' ). '/create ' ;
647+ $ url = rtrim ($ resourcesPath , '/ ' ) . '/create ' ;
643648 } elseif (request ('after-save ' ) == 'view ' ) {
644649 // view resource
645- $ url = rtrim ($ resourcesPath , '/ ' ). "/ {$ key }" ;
650+ $ url = rtrim ($ resourcesPath , '/ ' ) . "/ {$ key }" ;
646651 } elseif (request ('after-save ' ) == 'exit ' ) {
647652 // return message
648653 return trans ('admin.save_succeeded ' );
@@ -673,7 +678,7 @@ protected function isEditable(array $input = []): bool
673678 /**
674679 * Handle updates for single column.
675680 *
676- * @param int $id
681+ * @param int $id
677682 * @param array $data
678683 *
679684 * @return array|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response|Response
@@ -684,7 +689,7 @@ protected function handleColumnUpdates($id, $data)
684689
685690 if ($ this ->handleOrderable ($ id , $ data )) {
686691 return response ([
687- 'status ' => true ,
692+ 'status ' => true ,
688693 'message ' => trans ('admin.update_succeeded ' ),
689694 ]);
690695 }
@@ -702,7 +707,7 @@ protected function handleColumnUpdates($id, $data)
702707 protected function handleEditable (array $ input = []): array
703708 {
704709 if (array_key_exists ('_editable ' , $ input )) {
705- $ name = $ input ['name ' ];
710+ $ name = $ input ['name ' ];
706711 $ value = $ input ['value ' ];
707712
708713 Arr::forget ($ input , ['pk ' , 'value ' , 'name ' ]);
@@ -715,7 +720,7 @@ protected function handleEditable(array $input = []): array
715720 /**
716721 * Handle orderable update.
717722 *
718- * @param int $id
723+ * @param int $id
719724 * @param array $input
720725 *
721726 * @return bool
@@ -768,7 +773,7 @@ protected function updateRelation($relationsData)
768773 || $ relation instanceof Relations \BelongsTo;
769774
770775 $ isRelationUpdate = true ;
771- $ prepared = $ this ->prepareUpdate ([$ name => $ values ], $ oneToOneRelation , $ isRelationUpdate );
776+ $ prepared = $ this ->prepareUpdate ([$ name => $ values ], $ oneToOneRelation , $ isRelationUpdate );
772777
773778 if (empty ($ prepared )) {
774779 continue ;
@@ -839,7 +844,7 @@ protected function updateRelation($relationsData)
839844 * Prepare input data for update.
840845 *
841846 * @param array $updates
842- * @param bool $oneToOneRelation If column is one-to-one relation.
847+ * @param bool $oneToOneRelation If column is one-to-one relation.
843848 *
844849 * @return array
845850 */
@@ -876,13 +881,13 @@ protected function prepareUpdate(array $updates, $oneToOneRelation = false, $isR
876881
877882 /**
878883 * @param string|array $columns
879- * @param bool $containsDot
884+ * @param bool $containsDot
880885 *
881886 * @return bool
882887 */
883888 protected function isInvalidColumn ($ columns , $ containsDot = false ): bool
884889 {
885- foreach ((array ) $ columns as $ column ) {
890+ foreach ((array )$ columns as $ column ) {
886891 if ((!$ containsDot && Str::contains ($ column , '. ' ))
887892 || ($ containsDot && !Str::contains ($ column , '. ' ))) {
888893 return true ;
@@ -955,13 +960,13 @@ protected function isHasOneRelation($inserts): bool
955960 */
956961 public function ignore ($ fields ): self
957962 {
958- $ this ->ignored = array_merge ($ this ->ignored , (array ) $ fields );
963+ $ this ->ignored = array_merge ($ this ->ignored , (array )$ fields );
959964
960965 return $ this ;
961966 }
962967
963968 /**
964- * @param array $data
969+ * @param array $data
965970 * @param string|array $columns
966971 *
967972 * @return array|mixed
@@ -1055,7 +1060,7 @@ protected function setFieldValue($id)
10551060 /**
10561061 * Add a fieldset to form.
10571062 *
1058- * @param string $title
1063+ * @param string $title
10591064 * @param Closure $setCallback
10601065 *
10611066 * @return Field\Fieldset
@@ -1178,7 +1183,7 @@ public function setAction($action): self
11781183 public function setWidth ($ fieldWidth = 8 , $ labelWidth = 2 ): self
11791184 {
11801185 $ this ->fields ()->each (function ($ field ) use ($ fieldWidth , $ labelWidth ) {
1181- /* @var Field $field */
1186+ /* @var Field $field */
11821187 $ field ->setWidth ($ fieldWidth , $ labelWidth );
11831188 });
11841189
@@ -1426,7 +1431,7 @@ public function render()
14261431 * Get or set input data.
14271432 *
14281433 * @param string $key
1429- * @param null $value
1434+ * @param null $value
14301435 *
14311436 * @return array|mixed
14321437 */
@@ -1442,7 +1447,7 @@ public function input($key, $value = null)
14421447 /**
14431448 * Add a new layout column.
14441449 *
1445- * @param int $width
1450+ * @param int $width
14461451 * @param \Closure $closure
14471452 *
14481453 * @return $this
@@ -1480,7 +1485,7 @@ public function __get($name)
14801485 * Setter.
14811486 *
14821487 * @param string $name
1483- * @param mixed $value
1488+ * @param mixed $value
14841489 *
14851490 * @return array
14861491 */
@@ -1505,7 +1510,7 @@ public function __isset($name)
15051510 * Generate a Field object and add to form builder if Field exists.
15061511 *
15071512 * @param string $method
1508- * @param array $arguments
1513+ * @param array $arguments
15091514 *
15101515 * @return Field
15111516 */
0 commit comments