CountryController.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Http\Controllers\Admin\Countries;
  3. use App\Shop\Countries\Repositories\CountryRepository;
  4. use App\Shop\Countries\Repositories\Interfaces\CountryRepositoryInterface;
  5. use App\Shop\Countries\Requests\UpdateCountryRequest;
  6. use App\Http\Controllers\Controller;
  7. class CountryController extends Controller
  8. {
  9. private $countryRepo;
  10. public function __construct(CountryRepositoryInterface $countryRepository)
  11. {
  12. $this->countryRepo = $countryRepository;
  13. }
  14. /**
  15. * Display a listing of the resource.
  16. *
  17. * @return \Illuminate\Http\Response
  18. */
  19. public function index()
  20. {
  21. $list = $this->countryRepo->listCountries('created_at', 'desc');
  22. return view('admin.countries.list', [
  23. 'countries' => $this->countryRepo->paginateArrayResults($list->all(), 10)
  24. ]);
  25. }
  26. /**
  27. * Display the specified resource.
  28. *
  29. * @param int $id
  30. * @return \Illuminate\Http\Response
  31. */
  32. public function show(int $id)
  33. {
  34. $country = $this->countryRepo->findCountryById($id);
  35. $countryRepo = new CountryRepository($country);
  36. $provinces = $countryRepo->findProvinces();
  37. return view('admin.countries.show', [
  38. 'country' => $country,
  39. 'provinces' => $this->countryRepo->paginateArrayResults($provinces->toArray())
  40. ]);
  41. }
  42. /**
  43. * Show the form for editing the specified resource.
  44. *
  45. * @param int $id
  46. * @return \Illuminate\Http\Response
  47. */
  48. public function edit($id)
  49. {
  50. return view('admin.countries.edit', ['country' => $this->countryRepo->findCountryById($id)]);
  51. }
  52. /**
  53. * Update the specified resource in storage.
  54. *
  55. * @param UpdateCountryRequest $request
  56. * @param int $id
  57. * @return \Illuminate\Http\Response
  58. */
  59. public function update(UpdateCountryRequest $request, $id)
  60. {
  61. $country = $this->countryRepo->findCountryById($id);
  62. $update = new CountryRepository($country);
  63. $update->updateCountry($request->except('_method', '_token'));
  64. $request->session()->flash('message', 'Update successful');
  65. return redirect()->route('admin.countries.edit', $id);
  66. }
  67. }