Advertisement
vitareinforce

about controller

Dec 29th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.55 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers\Contents;
  4.  
  5. use App\Http\Controllers\Controller;
  6. use App\Models\Corporate;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\Auth;
  9. use Illuminate\Support\Facades\Redirect;
  10.  
  11. class AboutsController extends Controller
  12. {
  13. /**
  14. * Constructor
  15. *
  16. * @return void
  17. */
  18. public function __construct() {
  19.  
  20. }
  21.  
  22. /**
  23. * Display a listing of the resource.
  24. *
  25. * @return \Illuminate\Http\Response
  26. */
  27. public function index()
  28. {
  29. if (!Auth::check())
  30. {
  31. return redirect()->route('login');
  32. }
  33.  
  34. return view('dashboard.contents.abouts.index');
  35. }
  36.  
  37. /**
  38. * Display a listing of the resource.
  39. *
  40. * @return \Illuminate\Http\Response
  41. */
  42. public function csrIndex()
  43. {
  44. if (!Auth::check())
  45. {
  46. return redirect()->route('login');
  47. }
  48.  
  49. $csr = json_decode(Corporate::all('csr')[0]->csr);
  50. return view('dashboard.contents.abouts.csr.index', ['csr' => $csr]);
  51. }
  52.  
  53. /**
  54. * Display a listing of the resource.
  55. *
  56. * @return \Illuminate\Http\Response
  57. */
  58. public function csrCreate()
  59. {
  60. if (!Auth::check())
  61. {
  62. return redirect()->route('login');
  63. }
  64.  
  65. return view('dashboard.contents.abouts.csr.create');
  66. }
  67.  
  68. /**
  69. * Display a listing of the resource.
  70. *
  71. * @return \Illuminate\Http\Response
  72. */
  73. public function csrEdit($id)
  74. {
  75. if (!Auth::check())
  76. {
  77. return redirect()->route('login');
  78. }
  79.  
  80. $csr = json_decode(Corporate::all('csr')[0]->csr)[$id];
  81. return view('dashboard.contents.abouts.csr.update', ['csr' => $csr, 'id' => $id]);
  82. }
  83.  
  84. /**
  85. * Display a listing of the resource.
  86. *
  87. * @return \Illuminate\Http\Response
  88. */
  89. public function csrStore(Request $request)
  90. {
  91. if (!Auth::check())
  92. {
  93. return redirect()->route('login');
  94. }
  95.  
  96. $csr = Corporate::find(1);
  97. $existingdata = json_decode(Corporate::all('csr')[0]->csr);
  98. $newdata = json_decode('{ "title_en": "'.$request->title_en.'", "title_id": "'.$request->title_id.'", "content_en": "'.$request->content_en.', "content_id": "'.$request->content_id.', "datetime": "'.date('Y-m-d H:i:s').'" }');
  99. $result = array_push($existingdata, $newdata);
  100. $csr->update([
  101. 'csr' => json_encode($existingdata)
  102. ]);
  103. return redirect()->route('abouts.csrIndex')->with('alert-success', 'Data berhasil ditambah!');
  104. }
  105.  
  106. /**
  107. * Display a listing of the resource.
  108. *
  109. * @return \Illuminate\Http\Response
  110. */
  111. public function csrUpdate(Request $request, $id)
  112. {
  113. if (!Auth::check())
  114. {
  115. return redirect()->route('login');
  116. }
  117.  
  118. $csr = Corporate::find(1);
  119. $existingdata = json_decode(Corporate::all('csr')[0]->csr);
  120. $existingdata[$id] = json_decode('{ "title_en": "'.$request->title_en.'", "title_id": "'.$request->title_id.'", "content_en": "'.$request->content_en.', "content_id": "'.$request->content_id.', "datetime": "'.date('Y-m-d H:i:s').'" }');
  121. $csr->update([
  122. 'csr' => json_encode($existingdata)
  123. ]);
  124. return redirect()->route('abouts.csrIndex')->with('alert-success', 'Data berhasil diubah!');
  125. }
  126.  
  127. /**
  128. * Display a listing of the resource.
  129. *
  130. * @return \Illuminate\Http\Response
  131. */
  132. public function csrDestroy($id)
  133. {
  134. if (!Auth::check())
  135. {
  136. return redirect()->route('login');
  137. }
  138.  
  139. $social = Corporate::find(1);
  140. $existingdata = json_decode(Corporate::all('csr')[0]->csr);
  141. unset($existingdata[$id]);
  142. $csr->update([
  143. 'csr' => json_encode($existingdata)
  144. ]);
  145. return redirect()->route('abouts.csrIndex')->with('alert-success', 'Data berhasil dihapus!');
  146. }
  147.  
  148. /**
  149. * Display a listing of the resource.
  150. *
  151. * @return \Illuminate\Http\Response
  152. */
  153. public function socialIndex()
  154. {
  155. if (!Auth::check())
  156. {
  157. return redirect()->route('login');
  158. }
  159.  
  160. $social = json_decode(Corporate::all('social_media')[0]->social_media);
  161. return view('dashboard.contents.abouts.social.index', ['social' => $social]);
  162. }
  163.  
  164. /**
  165. * Display a listing of the resource.
  166. *
  167. * @return \Illuminate\Http\Response
  168. */
  169. public function socialCreate()
  170. {
  171. if (!Auth::check())
  172. {
  173. return redirect()->route('login');
  174. }
  175.  
  176. return view('dashboard.contents.abouts.social.create');
  177. }
  178.  
  179. /**
  180. * Display a listing of the resource.
  181. *
  182. * @return \Illuminate\Http\Response
  183. */
  184. public function socialEdit($id)
  185. {
  186. if (!Auth::check())
  187. {
  188. return redirect()->route('login');
  189. }
  190.  
  191. $social = json_decode(Corporate::all('social_media')[0]->social_media)[$id];
  192. return view('dashboard.contents.abouts.social.update', ['social' => $social, 'id' => $id]);
  193. }
  194.  
  195. /**
  196. * Display a listing of the resource.
  197. *
  198. * @return \Illuminate\Http\Response
  199. */
  200. public function socialStore(Request $request)
  201. {
  202. if (!Auth::check())
  203. {
  204. return redirect()->route('login');
  205. }
  206.  
  207. $social = Corporate::find(1);
  208. $existingdata = json_decode(Corporate::all('social_media')[0]->social_media);
  209. $newdata = json_decode('{ "media": "'.$request->media.'", "link": "'.$request->link.'" }');
  210. $result = array_push($existingdata, $newdata);
  211. $social->update([
  212. 'social_media' => json_encode($existingdata)
  213. ]);
  214. return redirect()->route('abouts.socialIndex')->with('alert-success', 'Data berhasil ditambah!');
  215. }
  216.  
  217. /**
  218. * Display a listing of the resource.
  219. *
  220. * @return \Illuminate\Http\Response
  221. */
  222. public function socialUpdate(Request $request, $id)
  223. {
  224. if (!Auth::check())
  225. {
  226. return redirect()->route('login');
  227. }
  228.  
  229. $social = Corporate::find(1);
  230. $existingdata = json_decode(Corporate::all('social_media')[0]->social_media);
  231. $existingdata[$id] = json_decode('{ "media": "'.$request->media.'", "link": "'.$request->link.'" }');
  232. $social->update([
  233. 'social_media' => json_encode($existingdata)
  234. ]);
  235. return redirect()->route('abouts.socialIndex')->with('alert-success', 'Data berhasil diubah!');
  236. }
  237.  
  238. /**
  239. * Display a listing of the resource.
  240. *
  241. * @return \Illuminate\Http\Response
  242. */
  243. public function socialDestroy($id)
  244. {
  245. if (!Auth::check())
  246. {
  247. return redirect()->route('login');
  248. }
  249.  
  250. $social = Corporate::find(1);
  251. $existingdata = json_decode(Corporate::all('social_media')[0]->social_media);
  252. unset($existingdata[$id]);
  253. $social->update([
  254. 'social_media' => json_encode($existingdata)
  255. ]);
  256. return redirect()->route('abouts.socialIndex')->with('alert-success', 'Data berhasil dihapus!');
  257. }
  258.  
  259. /**
  260. * Display a listing of the resource.
  261. *
  262. * @return \Illuminate\Http\Response
  263. */
  264. public function timelineIndex()
  265. {
  266. if (!Auth::check())
  267. {
  268. return redirect()->route('login');
  269. }
  270.  
  271. $timeline = json_decode(Corporate::all('timelines')[0]->timelines);
  272. return view('dashboard.contents.abouts.timeline.index', ['timeline' => $timeline]);
  273. }
  274.  
  275. /**
  276. * Display a listing of the resource.
  277. *
  278. * @return \Illuminate\Http\Response
  279. */
  280. public function timelineCreate()
  281. {
  282. if (!Auth::check())
  283. {
  284. return redirect()->route('login');
  285. }
  286.  
  287. return view('dashboard.contents.abouts.timeline.create');
  288. }
  289.  
  290. /**
  291. * Display a listing of the resource.
  292. *
  293. * @return \Illuminate\Http\Response
  294. */
  295. public function timelineEdit($id)
  296. {
  297. if (!Auth::check())
  298. {
  299. return redirect()->route('login');
  300. }
  301.  
  302. $timeline = json_decode(Corporate::all('timelines')[0]->timelines)[$id];
  303. return view('dashboard.contents.abouts.timeline.update', ['timeline' => $timeline, 'id' => $id]);
  304. }
  305.  
  306. /**
  307. * Display a listing of the resource.
  308. *
  309. * @return \Illuminate\Http\Response
  310. */
  311. public function timelineStore(Request $request)
  312. {
  313. if (!Auth::check())
  314. {
  315. return redirect()->route('login');
  316. }
  317.  
  318. $timeline = Corporate::find(1);
  319. $existingdata = json_decode(Corporate::all('timelines')[0]->timelines);
  320. $newdata = json_decode('{ "year": '.$request->year.', "event": '.json_encode($request->event).' }');
  321. $result = array_push($existingdata, $newdata);
  322. $timeline->update([
  323. 'timelines' => json_encode($existingdata)
  324. ]);
  325. return redirect()->route('abouts.timelineIndex')->with('alert-success', 'Data berhasil ditambah!');
  326. }
  327.  
  328. /**
  329. * Display a listing of the resource.
  330. *
  331. * @return \Illuminate\Http\Response
  332. */
  333. public function timelineUpdate(Request $request, $id)
  334. {
  335. if (!Auth::check())
  336. {
  337. return redirect()->route('login');
  338. }
  339.  
  340. $timeline = Corporate::find(1);
  341. $existingdata = json_decode(Corporate::all('timelines')[0]->timelines);
  342. $existingdata[$id] = json_decode('{ "year": '.$request->year.', "event": '.json_encode($request->event).' }');
  343. $timeline->update([
  344. 'timelines' => json_encode($existingdata)
  345. ]);
  346. return redirect()->route('abouts.timelineIndex')->with('alert-success', 'Data berhasil diubah!');
  347. }
  348.  
  349. /**
  350. * Display a listing of the resource.
  351. *
  352. * @return \Illuminate\Http\Response
  353. */
  354. public function timelineDestroy($id)
  355. {
  356. if (!Auth::check())
  357. {
  358. return redirect()->route('login');
  359. }
  360.  
  361. $timeline = Corporate::find(1);
  362. $existingdata = json_decode(Corporate::all('timelines')[0]->timelines);
  363. unset($existingdata[$id]);
  364. $timeline->update([
  365. 'timelines' => json_encode($existingdata)
  366. ]);
  367. return redirect()->route('abouts.timelineIndex')->with('alert-success', 'Data berhasil dihapus!');
  368. }
  369.  
  370. /**
  371. * Show the form for creating a new resource.
  372. *
  373. * @return \Illuminate\Http\Response
  374. */
  375. public function create()
  376. {
  377. if (!Auth::check())
  378. {
  379. return redirect()->route('login');
  380. }
  381.  
  382. return view('dashboard.contents.abouts.create');
  383. }
  384.  
  385. /**
  386. * Store a newly created resource in storage.
  387. *
  388. * @param \Illuminate\Http\Request $request
  389. * @return \Illuminate\Http\Response
  390. */
  391. public function store(Request $request)
  392. {
  393. if (!Auth::check())
  394. {
  395. return redirect()->route('login');
  396. }
  397. }
  398.  
  399. /**
  400. * Display the specified resource.
  401. *
  402. * @param int $id
  403. * @return \Illuminate\Http\Response
  404. */
  405. public function show($id)
  406. {
  407. if (!Auth::check())
  408. {
  409. return redirect()->route('login');
  410. }
  411.  
  412. return view('dashboard.contents.abouts.view');
  413. }
  414.  
  415. /**
  416. * Show the form for editing the specified resource.
  417. *
  418. * @param int $id
  419. * @return \Illuminate\Http\Response
  420. */
  421. public function edit($id)
  422. {
  423. if (!Auth::check())
  424. {
  425. return redirect()->route('login');
  426. }
  427.  
  428. return view('dashboard.contents.abouts.update');
  429. }
  430.  
  431. /**
  432. * Update the specified resource in storage.
  433. *
  434. * @param \Illuminate\Http\Request $request
  435. * @param int $id
  436. * @return \Illuminate\Http\Response
  437. */
  438. public function update(Request $request, $sectionName)
  439. {
  440. if (!Auth::check())
  441. {
  442. return redirect()->route('login');
  443. }
  444.  
  445. }
  446.  
  447. /**
  448. * Remove the specified resource from storage.
  449. *
  450. * @param int $id
  451. * @return \Illuminate\Http\Response
  452. */
  453. public function destroy($id)
  454. {
  455. if (!Auth::check())
  456. {
  457. return redirect()->route('login');
  458. }
  459. }
  460. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement