|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Helpers\Helper; |
|
6
|
|
|
use App\Http\Requests\QuoteSearchRequest; |
|
7
|
|
|
use App\Http\Requests\QuoteStoreRequest; |
|
8
|
|
|
use App\Models\Quote; |
|
9
|
|
|
use App\Services\QuoteService; |
|
10
|
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization; |
|
11
|
|
|
|
|
12
|
|
|
class QuoteController extends Controller |
|
13
|
|
|
{ |
|
14
|
|
|
private QuoteService $quoteService; |
|
15
|
|
|
|
|
16
|
|
|
public function __construct( |
|
17
|
|
|
QuoteService $quoteService |
|
18
|
|
|
) { |
|
19
|
|
|
$this->quoteService = $quoteService; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Display a listing of the resource. |
|
25
|
|
|
* |
|
26
|
|
|
* @param \App\Http\Requests\QuoteSearchRequest $request |
|
27
|
|
|
* |
|
28
|
|
|
* @return \Illuminate\Contracts\View\View |
|
29
|
|
|
*/ |
|
30
|
|
|
public function index(QuoteSearchRequest $request) |
|
31
|
|
|
{ |
|
32
|
|
|
$searchParameters = Helper::getSearchParameters($request, Quote::SEARCH_PARAMETERS); |
|
33
|
|
|
|
|
34
|
|
|
$quotes = $this->quoteService->getQuotes(20, $searchParameters); |
|
35
|
|
|
$statuses = Quote::PUBLISHING_STATUS; |
|
36
|
|
|
$showWhereOptions = Quote::SHOW_WHERE_OPTIONS; |
|
37
|
|
|
|
|
38
|
|
|
return view('quotes.index', [ |
|
39
|
|
|
'quotes' => $quotes, |
|
40
|
|
|
'searchParameters' => $searchParameters, |
|
41
|
|
|
'statuses' => $statuses, |
|
42
|
|
|
'showWhereOptions' => $showWhereOptions, |
|
43
|
|
|
]); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Show the form for creating a new resource. |
|
48
|
|
|
* |
|
49
|
|
|
* @return \Illuminate\Contracts\View\View |
|
50
|
|
|
*/ |
|
51
|
|
|
public function create() |
|
52
|
|
|
{ |
|
53
|
|
|
$countriesAvailableForTranslations = LaravelLocalization::getSupportedLocales(); |
|
54
|
|
|
return view('quotes.create', [ |
|
55
|
|
|
'countriesAvailableForTranslations' => $countriesAvailableForTranslations, |
|
56
|
|
|
]); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Store a newly created resource in storage. |
|
61
|
|
|
* |
|
62
|
|
|
* @param \App\Http\Requests\QuoteStoreRequest $request |
|
63
|
|
|
* |
|
64
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
65
|
|
|
*/ |
|
66
|
|
|
public function store(QuoteStoreRequest $request) |
|
67
|
|
|
{ |
|
68
|
|
|
$quote = $this->quoteService->createQuote($request); |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
return redirect()->route('quotes.index') |
|
71
|
|
|
->with('success', 'Quote created successfully'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Show the form for editing the specified resource. |
|
76
|
|
|
* |
|
77
|
|
|
* @param int $quoteId |
|
78
|
|
|
* |
|
79
|
|
|
* @return \Illuminate\Contracts\View\View |
|
80
|
|
|
*/ |
|
81
|
|
|
public function edit(int $quoteId) |
|
82
|
|
|
{ |
|
83
|
|
|
$quote = $this->quoteService->getById($quoteId); |
|
84
|
|
|
$countriesAvailableForTranslations = LaravelLocalization::getSupportedLocales(); |
|
85
|
|
|
|
|
86
|
|
|
return view('quotes.edit', [ |
|
87
|
|
|
'quote' => $quote, |
|
88
|
|
|
'countriesAvailableForTranslations' => $countriesAvailableForTranslations, |
|
89
|
|
|
]); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Update the specified resource in storage. |
|
94
|
|
|
* |
|
95
|
|
|
* @param \App\Http\Requests\QuoteStoreRequest $request |
|
96
|
|
|
* @param int $quoteId |
|
97
|
|
|
* |
|
98
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
99
|
|
|
*/ |
|
100
|
|
|
public function update(QuoteStoreRequest $request, int $quoteId) |
|
101
|
|
|
{ |
|
102
|
|
|
$quote = $this->quoteService->updateQuote($request, $quoteId); |
|
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
return redirect()->route('quotes.index') |
|
105
|
|
|
->with('success', 'Quote updated successfully'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Remove the specified resource from storage. |
|
110
|
|
|
* |
|
111
|
|
|
* @param int $quoteId |
|
112
|
|
|
* |
|
113
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
114
|
|
|
*/ |
|
115
|
|
|
public function destroy(int $quoteId) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->quoteService->deleteQuote($quoteId); |
|
118
|
|
|
|
|
119
|
|
|
return redirect()->route('quotes.index') |
|
120
|
|
|
->with('success', 'Quote deleted successfully'); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
|