/
SightsController.php
83 lines (63 loc) · 2.01 KB
/
SightsController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php namespace Sightseeing\Controllers;
use Input;
use Laracasts\Commander\CommanderTrait;
use Sightseeing\Repositories\Sight\SightRepository;
use Sightseeing\Sights\DeleteImageCommand;
use Sightseeing\Sights\UploadImageCommand;
class SightsController extends BaseController {
use CommanderTrait;
/**
* @var SightRepository
*/
private $sightRepository;
function __construct(SightRepository $sightRepository)
{
$this->sightRepository = $sightRepository;
}
public function index()
{
$sights = $this->sightRepository->getAll(['city', 'images']);
return \View::make('sights.index')
->with('title', 'Manage Sights')
->with('sights', $sights);
}
public function show($sightId)
{
$sight = $this->sightRepository->getById($sightId);
return \View::make('sights.show')
->with('title', 'Edit ' . $sight->name)
->with('sight', $sight);
}
public function edit($sightId)
{
$this->sightRepository->updateById($sightId, Input::only('name', 'description'));
return \Redirect::back()
->with('message', 'This sight was successfully updated');
}
public function upload($sightId)
{
$input = array(
'id' => $sightId,
'image' => Input::file('image')
);
$this->execute(UploadImageCommand::class, $input);
}
public function showImage($imageId)
{
$image = $this->sightRepository->getImageById($imageId);
$sight = $image->sight;
return \View::make('sights.image')
->with('title', 'Editing image')
->with('image', $image)
->with('sight', $sight);
}
public function deleteImage($imageId)
{
$input = array(
'imageId' => $imageId,
);
$this->execute(DeleteImageCommand::class, $input);
return \Redirect::route('sight.index')
->with('message', 'Image deleted successfully');
}
}