77use App \Http \Requests ;
88use App \Models \Content ;
99use App \Models \PageContent ;
10+ use Illuminate \Http \Request ;
1011use Illuminate \Http \UploadedFile ;
1112use App \Http \Controllers \Admin \AdminController ;
1213use Titan \Models \Traits \ImageThumb ;
1314
1415class PageContentController extends AdminController
1516{
17+
18+ /**
19+ * Display a listing of content.
20+ *
21+ * @param Page $page
22+ * @return Response
23+ */
24+ public function index (Page $ page )
25+ {
26+ save_resource_url ();
27+
28+ $ page ->load ('sections ' );
29+
30+ return $ this ->view ('pages.components.page_components ' )->with ('page ' , $ page );
31+ }
32+
1633 /**
1734 * Show the form for creating a new content.
1835 *
@@ -21,12 +38,35 @@ class PageContentController extends AdminController
2138 */
2239 public function create (Page $ page )
2340 {
24- // create new content (used to link media and documents to)
25- $ item = PageContent::create ();
26-
2741 return $ this ->view ('pages.components.content ' )
28- ->with ('page ' , $ page )
29- ->with ('item ' , $ item );
42+ ->with ('page ' , $ page );
43+ }
44+
45+ /**
46+ * Store a newly created news in storage.
47+ *
48+ * @param Request $request
49+ * @return array
50+ */
51+ public function store (Request $ request )
52+ {
53+
54+ if (is_null (request ()->file ('media ' ))) {
55+ $ attributes = request ()->validate (array_except (PageContent::$ rules , 'media ' ),
56+ PageContent::$ messages );
57+ }
58+ else {
59+ $ attributes = request ()->validate (PageContent::$ rules , PageContent::$ messages );
60+
61+ $ media = $ this ->moveAndCreatePhoto ($ attributes ['media ' ]);
62+ if ($ media ) {
63+ $ attributes ['media ' ] = $ media ;
64+ }
65+ }
66+
67+ $ pageContent = $ this ->createEntry (PageContent::class, $ attributes );
68+
69+ return redirect ('admin/pages/ ' .$ request ->page_id .'/sections/content/ ' .$ pageContent ->id .'/edit ' );
3070 }
3171
3272 /**
@@ -38,6 +78,7 @@ public function create(Page $page)
3878 */
3979 public function edit (Page $ page , PageContent $ content )
4080 {
81+
4182 return $ this ->view ('pages.components.content ' )
4283 ->with ('page ' , $ page )
4384 ->with ('item ' , $ content );
@@ -68,11 +109,48 @@ public function update(Page $page, PageContent $content)
68109 unset($ attributes ['page_id ' ]);
69110 $ item = $ this ->updateEntry ($ content , $ attributes );
70111
71- $ page ->attachComponent ($ item );
112+ return redirect_to_resource ();
113+ }
114+
115+ /**
116+ * Remove the specified content from storage.
117+ *
118+ * @param Page $page
119+ * @param PageContent $section
120+ * @return Response
121+ * @internal param $page_section
122+ */
123+ public function destroy (Page $ page , PageContent $ section )
124+ {
125+ // delete page_content
126+ $ this ->deleteEntry ($ section , request ());
127+
128+ log_activity ('Page Component Deleted ' , 'A Page Content was successfully removed from the Page ' , $ section );
72129
73130 return redirect_to_resource ();
74131 }
75132
133+ /**
134+ * @param Page $page
135+ * @return array
136+ */
137+ public function updateOrder (Page $ page )
138+ {
139+ $ items = json_decode (request ('list ' ), true );
140+
141+ foreach ($ items as $ key => $ item ) {
142+
143+ $ row = PageContent::find ($ item ['id ' ]);
144+ if ($ row ) {
145+ $ row ->update ([
146+ 'list_order ' => ($ key + 1 )
147+ ]);
148+ }
149+ }
150+
151+ return ['result ' => 'success ' ];
152+ }
153+
76154 /**
77155 * Save Image in Storage, crop image and save in public/uploads/images
78156 * @param UploadedFile $file
0 commit comments