@@ -47,7 +47,7 @@ public function index(PostType $type, Request $request, bool $trashed = false)
4747 $ per_page = $ this ->getPerPage ($ request );
4848
4949 $ posts = $ type ->posts ()
50- ->orderBy ($ orderby , $ order );
50+ ->orderBy ($ orderby , $ order );
5151
5252 $ search = null ;
5353 if ($ search = $ request ->input ('search ' )) {
@@ -92,7 +92,7 @@ public function index(PostType $type, Request $request, bool $trashed = false)
9292 }
9393
9494 $ posts = $ posts ->paginate ($ per_page )
95- ->appends ($ request ->except ('page ' ));
95+ ->appends ($ request ->except ('page ' ));
9696
9797 return view ('cms::admin.posts.index ' , compact ('posts ' , 'type ' , 'title ' , 'per_page ' , 'search ' , 'trashed ' ));
9898 }
@@ -131,7 +131,7 @@ public function store(PostType $type, PostsRequest $request)
131131
132132 $ post ->lang = $ request ->input ('lang ' , app ()->getLocale ());
133133
134- if ($ request ->has ('department ' ) && method_exists ($ post , 'department ' )) {
134+ if ($ request ->has ('department ' ) && method_exists ($ post , 'department ' ) && \ Illuminate \ Support \ Facades \Schema:: hasColumn ( $ post -> getTable (), ' department_id ' ) ) {
135135 $ post ->department ()->associate ($ request ->input ('department ' ));
136136 }
137137
@@ -199,7 +199,7 @@ public function update(PostsRequest $request, PostType $type, Post $post)
199199 $ this ->authorize ('update ' , $ post );
200200
201201 // If this is not a translation, set lang
202- if ((! $ request ->input ('is_translation ' )) && $ request ->input ('lang ' )) {
202+ if ((!$ request ->input ('is_translation ' )) && $ request ->input ('lang ' )) {
203203 $ post ->lang = $ request ->input ('lang ' );
204204 app ()->setLocale ($ post ->lang ->value );
205205 }
@@ -226,7 +226,7 @@ public function update(PostsRequest $request, PostType $type, Post $post)
226226 $ post ->recently_updated = $ request ->input ('recently_updated ' , false );
227227 }
228228
229- if ($ request ->has ('department ' ) && method_exists ($ post , 'department ' )) {
229+ if ($ request ->has ('department ' ) && method_exists ($ post , 'department ' ) && \ Illuminate \ Support \ Facades \Schema:: hasColumn ( $ post -> getTable (), ' department_id ' ) ) {
230230 $ post ->department ()->associate ($ request ->input ('department ' ));
231231 }
232232
@@ -293,7 +293,7 @@ public function destroy(PostType $type, Post $post, Request $request)
293293 {
294294 $ this ->authorize ('delete ' , $ post );
295295
296- if (! $ post ->delete ()) {
296+ if (!$ post ->delete ()) {
297297 if ($ request ->expectsJson ()) {
298298 return response ()->json (false , 500 );
299299 }
@@ -327,14 +327,14 @@ public function forceDelete(PostType $postType, $id, Request $request)
327327 {
328328 //find the model
329329 $ post = $ postType ->posts ()
330- ->onlyTrashed ()
331- ->where ('id ' , $ id )
332- ->firstOrFail ();
330+ ->onlyTrashed ()
331+ ->where ('id ' , $ id )
332+ ->firstOrFail ();
333333
334334 $ this ->authorize ('forceDelete ' , $ post );
335335
336336 // send error
337- if (! $ post ->forceDelete ()) {
337+ if (!$ post ->forceDelete ()) {
338338 if ($ request ->expectsJson ()) {
339339 return response ()->json (false , 500 );
340340 }
@@ -358,14 +358,14 @@ public function restore(PostType $postType, $id, Request $request)
358358 {
359359 //find the model
360360 $ post = $ postType ->posts ()
361- ->onlyTrashed ()
362- ->where ('id ' , $ id )
363- ->firstOrFail ();
361+ ->onlyTrashed ()
362+ ->where ('id ' , $ id )
363+ ->firstOrFail ();
364364
365365 $ this ->authorize ('restore ' , $ post );
366366
367367 // send error
368- if (! $ post ->restore ()) {
368+ if (!$ post ->restore ()) {
369369 if ($ request ->expectsJson ()) {
370370 return response ()->json (false , 500 );
371371 }
@@ -390,8 +390,8 @@ public function bulk(PostType $type, Request $request)
390390 $ this ->authorize ('viewAny ' , $ type );
391391
392392 $ this ->validate ($ request , [
393- 'action ' => 'required|in:delete,publish,draft,markAsPending ' ,
394- 'posts ' => 'required|array ' ,
393+ 'action ' => 'required|in:delete,publish,draft,markAsPending ' ,
394+ 'posts ' => 'required|array ' ,
395395 'posts.* ' => 'exists:posts,id,type, ' . $ type ->slug ,
396396 ]);
397397
@@ -405,13 +405,13 @@ public function bulk(PostType $type, Request $request)
405405 $ this ->authorize ('delete ' , $ type );
406406
407407 $ type ->posts ()
408- ->whereIn ('id ' , $ ids )
409- ->get ()
410- ->each (function (Post $ post ) {
411- if (auth ()->user ()->can ('delete ' , $ post )) {
412- $ post ->delete ();
413- }
414- });
408+ ->whereIn ('id ' , $ ids )
409+ ->get ()
410+ ->each (function (Post $ post ) {
411+ if (auth ()->user ()->can ('delete ' , $ post )) {
412+ $ post ->delete ();
413+ }
414+ });
415415 break ;
416416
417417 case 'reject ' :
@@ -427,18 +427,18 @@ public function bulk(PostType $type, Request $request)
427427 }
428428
429429 $ posts ->whereIn ('id ' , $ ids )
430- ->get ()
431- ->each (function (Post $ post ) use ($ action , $ type ) {
432- if (method_exists ($ post , $ action )) {
433- if ($ action == 'draft ' && auth ()->user ()->can ('update ' , $ post )) {
434- $ post ->{$ action }();
435- $ post ->save ();
436- } elseif ($ action != 'draft ' && auth ()->user ()->can ('publish ' , $ type )) {
437- $ post ->{$ action }();
438- $ post ->save ();
439- }
440- }
441- });
430+ ->get ()
431+ ->each (function (Post $ post ) use ($ action , $ type ) {
432+ if (method_exists ($ post , $ action )) {
433+ if ($ action == 'draft ' && auth ()->user ()->can ('update ' , $ post )) {
434+ $ post ->{$ action }();
435+ $ post ->save ();
436+ } elseif ($ action != 'draft ' && auth ()->user ()->can ('publish ' , $ type )) {
437+ $ post ->{$ action }();
438+ $ post ->save ();
439+ }
440+ }
441+ });
442442 break ;
443443 }
444444
0 commit comments