Created
March 8, 2018 01:33
-
-
Save jsdecena/6b998bf4b860ab69f989f0d84b8ea710 to your computer and use it in GitHub Desktop.
Carousel Controller Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers\Admin\Carousels; | |
use App\Http\Controllers\Controller; | |
use App\Shop\Carousels\Exceptions\CarouselNotFoundException; | |
use App\Shop\Carousels\Exceptions\CreateCarouselErrorException; | |
use App\Shop\Carousels\Exceptions\UpdateCarouselErrorException; | |
use App\Shop\Carousels\Repositories\CarouselRepository; | |
use App\Shop\Carousels\Repositories\CarouselRepositoryInterface; | |
use App\Shop\Carousels\Requests\CreateCarouselRequest; | |
use App\Shop\Carousels\Requests\UpdateCarouselRequest; | |
use Illuminate\Http\UploadedFile; | |
class CarouselController extends Controller | |
{ | |
/** | |
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | |
*/ | |
public function create() | |
{ | |
return view('admin.carousels.create'); | |
} | |
/** | |
* @param CreateCarouselRequest $request | |
* @return \Illuminate\Http\RedirectResponse | |
*/ | |
public function store(CreateCarouselRequest $request) | |
{ | |
try { | |
$data = $request->except('_token'); | |
if ($request->hasFile('image') && $request->file('image') instanceof UploadedFile) { | |
$data['src'] = $request->file('image')->store('carousels', ['disk' => 'public']); | |
} | |
$carouselRepo = new CarouselRepository(new Carousel); | |
$carouselRepo->createCarousel($data); | |
$request->session()->flash('message', 'Create carousel successful!'); | |
return redirect()->route('admin.carousel.index'); | |
} catch (CreateCarouselErrorException $e) { | |
$request->session()->flash('error', $e->getMessage()); | |
return redirect()->back()->withInput(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment