|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Http\Controllers\Admin; |
| 4 | + |
| 5 | +use Redirect; |
| 6 | +use App\Http\Requests; |
| 7 | +use App\Models\Banner; |
| 8 | +use Illuminate\Http\Request; |
| 9 | +use App\Http\Controllers\Admin\AdminController; |
| 10 | +use Titan\Controllers\Traits\UploadFile; |
| 11 | + |
| 12 | +class BannersController extends AdminController |
| 13 | +{ |
| 14 | + use UploadFile; |
| 15 | + |
| 16 | + /** |
| 17 | + * Display a listing of banner. |
| 18 | + * |
| 19 | + * @return Response |
| 20 | + */ |
| 21 | + public function index() |
| 22 | + { |
| 23 | + save_resource_url(); |
| 24 | + |
| 25 | + return $this->view('banners.index')->with('items', Banner::all()); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Show the form for creating a new banner. |
| 30 | + * |
| 31 | + * @return Response |
| 32 | + */ |
| 33 | + public function create() |
| 34 | + { |
| 35 | + return $this->view('banners.add_edit'); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Store a newly created banner in storage. |
| 40 | + * |
| 41 | + * @param Request $request |
| 42 | + * @return Response |
| 43 | + */ |
| 44 | + public function store(Request $request) |
| 45 | + { |
| 46 | + $this->validate($request, Banner::$rules, Banner::$messages); |
| 47 | + |
| 48 | + $photo = $this->uploadBanner($request->file('photo')); |
| 49 | + if ($photo) { |
| 50 | + $request->merge(['image' => $photo]); |
| 51 | + $banner = $this->createEntry(Banner::class, $request->except('photo')); |
| 52 | + } |
| 53 | + |
| 54 | + log_action('Banner Created', 'Banner was created ' . $banner->title); |
| 55 | + |
| 56 | + return redirect_to_resource(); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Display the specified banner. |
| 61 | + * |
| 62 | + * @param Banner $banner |
| 63 | + * @return Response |
| 64 | + */ |
| 65 | + public function show(Banner $banner) |
| 66 | + { |
| 67 | + return $this->view('banners.show')->with('item', $banner); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Show the form for editing the specified banner. |
| 72 | + * |
| 73 | + * @param Banner $banner |
| 74 | + * @return Response |
| 75 | + */ |
| 76 | + public function edit(Banner $banner) |
| 77 | + { |
| 78 | + return $this->view('banners.add_edit')->with('item', $banner); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Update the specified banner in storage. |
| 83 | + * |
| 84 | + * @param Banner $banner |
| 85 | + * @param Request $request |
| 86 | + * @return Response |
| 87 | + */ |
| 88 | + public function update(Banner $banner, Request $request) |
| 89 | + { |
| 90 | + if (is_null($request->file('photo'))) { |
| 91 | + $this->validate($request, array_except(Banner::$rules, 'photo'), Banner::$messages); |
| 92 | + } |
| 93 | + else { |
| 94 | + $this->validate($request, Banner::$rules, Banner::$messages); |
| 95 | + |
| 96 | + $photo = $this->uploadBanner($request->file('photo')); |
| 97 | + $request->merge(['image' => $photo]); |
| 98 | + } |
| 99 | + |
| 100 | + $this->updateEntry($banner, $request->except('photo')); |
| 101 | + |
| 102 | + log_action('Banner Updated', 'Banner was updated. ' . $banner->title); |
| 103 | + |
| 104 | + return redirect_to_resource(); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Remove the specified banner from storage. |
| 109 | + * |
| 110 | + * @param Banner $banner |
| 111 | + * @param Request $request |
| 112 | + * @return Response |
| 113 | + */ |
| 114 | + public function destroy(Banner $banner, Request $request) |
| 115 | + { |
| 116 | + $this->deleteEntry($banner, $request); |
| 117 | + |
| 118 | + return redirect_to_resource(); |
| 119 | + } |
| 120 | +} |
0 commit comments