@@ -82,73 +82,97 @@ public function create()
8282 return view ('panichd::admin.configuration.create ' );
8383 }
8484
85+ /**
86+ * Store a newly created Configuration in storage.
87+ *
88+ * @param Request $request
89+ *
90+ * @return \Illuminate\Http\RedirectResponse
91+ */
92+ public function store (Request $ request )
93+ {
94+ $ input = $ request ->all ();
95+
96+ $ configuration = new Configuration ();
97+ $ configuration ->create ($ input );
98+
99+ Session::flash ('configuration ' , 'Setting saved successfully. ' );
100+ \Cache::forget ('panichd::settings ' ); // refresh cached settings
101+ return redirect ()->action ('\PanicHD\PanicHD\Controllers\ConfigurationsController@index ' );
102+ }
103+
104+ /**
105+ * Show the form for editing the specified Configuration.
106+ *
107+ * @param int $id
108+ *
109+ * @return Response
110+ */
111+ public function edit ($ id )
112+ {
113+ $ configuration = Configuration::findOrFail ($ id );
114+ $ should_serialize = Setting::is_serialized ($ configuration ->value );
115+ $ default_serialized = Setting::is_serialized ($ configuration ->default );
116+
117+ return view ('panichd::admin.configuration.edit ' , compact ('configuration ' , 'should_serialize ' , 'default_serialized ' ));
118+ }
119+
120+ /**
121+ * Update the specified Configuration in storage.
122+ *
123+ * @param int $id
124+ * @param Request $request
125+ *
126+ * @return $this|\Illuminate\Http\RedirectResponse
127+ */
128+ public function update (Request $ request , $ id )
129+ {
130+ $ configuration = Configuration::findOrFail ($ id );
131+
132+ $ value = $ request ->value ;
133+
134+ if ($ request ->serialize ) {
135+ //if(!Hash::check($request->password, auth()->user()->password)){
136+ if (!Auth::attempt ($ request ->only ('password ' ), false , false )) {
137+ return back ()->withErrors ([trans ('panichd::admin.config-edit-auth-failed ' )]);
138+ }
139+ if (false === eval ('$value = serialize( ' .$ value .'); ' )) {
140+ return back ()->withErrors ([trans ('panichd::admin.config-edit-eval-error ' )]);
141+ }
142+ }
143+
144+ $ configuration ->update (['value ' => $ value , 'lang ' => $ request ->lang ]);
145+
146+ Session::flash ('configuration ' , trans ('panichd::admin.config-update-confirm ' , ['name ' => $ request ->name ]));
147+ // refresh cached settings
148+ \Cache::forget ('panichd::settings ' );
149+ \Cache::forget ('panichd::settings. ' .$ configuration ->slug );
150+
151+ return redirect ()->action ('\PanicHD\PanicHD\Controllers\ConfigurationsController@index ' );
152+ }
85153
86- /**
87- * Store a newly created Configuration in storage.
88- *
89- * @param Request $request
90- *
91- * @return \Illuminate\Http\RedirectResponse
92- */
93- public function store (Request $ request )
94- {
95- $ input = $ request ->all ();
96-
97- $ configuration = new Configuration ();
98- $ configuration ->create ($ input );
99-
100- Session::flash ('configuration ' , 'Setting saved successfully. ' );
101- \Cache::forget ('panichd::settings ' ); // refresh cached settings
102- return redirect ()->action ('\PanicHD\PanicHD\Controllers\ConfigurationsController@index ' );
103- }
104-
105- /**
106- * Show the form for editing the specified Configuration.
107- *
108- * @param int $id
109- *
110- * @return Response
111- */
112- public function edit ($ id )
113- {
114- $ configuration = Configuration::findOrFail ($ id );
115- $ should_serialize = Setting::is_serialized ($ configuration ->value );
116- $ default_serialized = Setting::is_serialized ($ configuration ->default );
117-
118- return view ('panichd::admin.configuration.edit ' , compact ('configuration ' , 'should_serialize ' , 'default_serialized ' ));
119- }
120-
121- /**
122- * Update the specified Configuration in storage.
123- *
124- * @param int $id
125- * @param Request $request
126- *
127- * @return $this|\Illuminate\Http\RedirectResponse
128- */
129- public function update (Request $ request , $ id )
130- {
131- $ configuration = Configuration::findOrFail ($ id );
132-
133- $ value = $ request ->value ;
134-
135- if ($ request ->serialize ) {
136- //if(!Hash::check($request->password, auth()->user()->password)){
137- if (!Auth::attempt ($ request ->only ('password ' ), false , false )) {
138- return back ()->withErrors ([trans ('panichd::admin.config-edit-auth-failed ' )]);
139- }
140- if (false === eval ('$value = serialize( ' .$ value .'); ' )) {
141- return back ()->withErrors ([trans ('panichd::admin.config-edit-eval-error ' )]);
142- }
143- }
144-
145- $ configuration ->update (['value ' => $ value , 'lang ' => $ request ->lang ]);
146-
147- Session::flash ('configuration ' , trans ('panichd::admin.config-update-confirm ' , ['name ' => $ request ->name ]));
148- // refresh cached settings
149- \Cache::forget ('panichd::settings ' );
150- \Cache::forget ('panichd::settings. ' .$ configuration ->slug );
151-
152- return redirect ()->action ('\PanicHD\PanicHD\Controllers\ConfigurationsController@index ' );
153- }
154+ /**
155+ * Update the specified Configuration in storage.
156+ *
157+ * @param int $id
158+ * @param Request $request
159+ *
160+ * @return $this|\Illuminate\Http\RedirectResponse
161+ */
162+ public function destroy (Request $ request , $ id )
163+ {
164+ $ configuration = Configuration::findOrFail ($ id );
165+ $ clone = clone $ configuration ;
166+
167+ $ value = $ request ->value ;
168+
169+ $ configuration ->delete ();
170+
171+ Session::flash ('status ' , trans ('panichd::admin.config-delete-confirm ' , ['name ' => $ clone ->slug ]));
172+ // refresh cached settings
173+ \Cache::forget ('panichd::settings ' );
174+ \Cache::forget ('panichd::settings. ' .$ clone ->slug );
175+
176+ return redirect ()->action ('\PanicHD\PanicHD\Controllers\ConfigurationsController@index ' );
177+ }
154178}
0 commit comments