Completed
Push — master ( de65e6...7b2528 )
by Roberts
45:15 queued 41:49
created
src/Admin/Form/Fields/BelongsToMany.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -23,9 +23,9 @@  discard block
 block discarded – undo
23 23
     {
24 24
         $list = Html::ul();
25 25
 
26
-        foreach( $this->getValue() as $item )
26
+        foreach ($this->getValue() as $item)
27 27
         {
28
-            $list->append( Html::li( $item ) );
28
+            $list->append(Html::li($item));
29 29
         }
30 30
 
31 31
         return (string) $list;
@@ -53,27 +53,27 @@  discard block
 block discarded – undo
53 53
     public function render()
54 54
     {
55 55
         $relatedModel = $this->getRelatedModel();
56
-        $checkboxes = $this->getRelatedModelOptions( $relatedModel );
56
+        $checkboxes = $this->getRelatedModelOptions($relatedModel);
57 57
 
58
-        $label = Html::label( $this->getLabel() )->addAttributes( [ 'for' => $this->getName() ] );
58
+        $label = Html::label($this->getLabel())->addAttributes([ 'for' => $this->getName() ]);
59 59
 
60
-        return Html::div( [
61
-            Html::div( $label )->addClass( 'label-wrap' ),
62
-            Html::div( $checkboxes )->addClass( 'value' )
63
-        ] )->addClass( 'field type-associated-set' );
60
+        return Html::div([
61
+            Html::div($label)->addClass('label-wrap'),
62
+            Html::div($checkboxes)->addClass('value')
63
+        ])->addClass('field type-associated-set');
64 64
     }
65 65
 
66 66
     /**
67 67
      * @param \Illuminate\Database\Eloquent\Model $relatedModel
68 68
      * @return Element[]
69 69
      */
70
-    public function getRelatedModelOptions( $relatedModel )
70
+    public function getRelatedModelOptions($relatedModel)
71 71
     {
72
-        $checkboxes = [];
72
+        $checkboxes = [ ];
73 73
 
74
-        $selectedOptions = $this->getValue()->pluck( $relatedModel->getKeyName() )->all();
74
+        $selectedOptions = $this->getValue()->pluck($relatedModel->getKeyName())->all();
75 75
 
76
-        foreach( $relatedModel::all() as $modelOption )
76
+        foreach ($relatedModel::all() as $modelOption)
77 77
         {
78 78
             $name = [
79 79
                 $this->getNameSpacedName(),
@@ -81,17 +81,17 @@  discard block
 block discarded – undo
81 81
             ];
82 82
 
83 83
             $checkbox = Html::checkbox()
84
-                ->setName( implode( '.', $name ) )
85
-                ->setValue( 1 );
84
+                ->setName(implode('.', $name))
85
+                ->setValue(1);
86 86
 
87
-            $checkbox->append( $checkbox->getLabel( (string) $modelOption ) );
87
+            $checkbox->append($checkbox->getLabel((string) $modelOption));
88 88
 
89
-            if( in_array( $modelOption->getKey(), $selectedOptions, true ) )
89
+            if (in_array($modelOption->getKey(), $selectedOptions, true))
90 90
             {
91 91
                 $checkbox->select();
92 92
             }
93 93
 
94
-            $checkboxes[] = Html::div( $checkbox )->addClass( 'type-associated-set-item' );
94
+            $checkboxes[ ] = Html::div($checkbox)->addClass('type-associated-set-item');
95 95
         }
96 96
 
97 97
         return $checkboxes;
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
     /**
101 101
      * @param Request $request
102 102
      */
103
-    public function beforeModelSave( Request $request )
103
+    public function beforeModelSave(Request $request)
104 104
     {
105 105
 
106 106
     }
@@ -108,28 +108,28 @@  discard block
 block discarded – undo
108 108
     /**
109 109
      * @param Request $request
110 110
      */
111
-    public function afterModelSave( Request $request )
111
+    public function afterModelSave(Request $request)
112 112
     {
113 113
         $relation = $this->getRelation();
114 114
 
115
-        $submittedIds = $request->input( $this->getNameSpacedName(), [] );
116
-        $existingIds = $this->getModel()->getAttribute( $this->getName() )
117
-            ->pluck( $this->getRelatedModel()->getKeyName() )
115
+        $submittedIds = $request->input($this->getNameSpacedName(), [ ]);
116
+        $existingIds = $this->getModel()->getAttribute($this->getName())
117
+            ->pluck($this->getRelatedModel()->getKeyName())
118 118
             ->toArray();
119 119
 
120
-        foreach( $existingIds as $id )
120
+        foreach ($existingIds as $id)
121 121
         {
122
-            if( !array_key_exists( $id, $submittedIds ) )
122
+            if (!array_key_exists($id, $submittedIds))
123 123
             {
124
-                $relation->detach( $id );
124
+                $relation->detach($id);
125 125
             }
126 126
         }
127 127
 
128
-        foreach( array_keys( $submittedIds ) as $id )
128
+        foreach (array_keys($submittedIds) as $id)
129 129
         {
130
-            if( !in_array( $id, $existingIds, true ) )
130
+            if (!in_array($id, $existingIds, true))
131 131
             {
132
-                $relation->attach( $id );
132
+                $relation->attach($id);
133 133
             }
134 134
         }
135 135
     }
Please login to merge, or discard this patch.