CityController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Http\Controllers\Admin\Cities;
  3. use App\Shop\Cities\Repositories\CityRepository;
  4. use App\Shop\Cities\Repositories\Interfaces\CityRepositoryInterface;
  5. use App\Shop\Cities\Requests\UpdateCityRequest;
  6. use App\Http\Controllers\Controller;
  7. class CityController extends Controller
  8. {
  9. /**
  10. * @var CityRepositoryInterface
  11. */
  12. private $cityRepo;
  13. /**
  14. * CityController constructor.
  15. *
  16. * @param CityRepositoryInterface $cityRepository
  17. */
  18. public function __construct(CityRepositoryInterface $cityRepository)
  19. {
  20. $this->cityRepo = $cityRepository;
  21. }
  22. /**
  23. * Show the edit form
  24. *
  25. * @param int $countryId
  26. * @param int $provinceId
  27. * @param string $city
  28. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  29. */
  30. public function edit($countryId, $provinceId, $city)
  31. {
  32. $city = $this->cityRepo->findCityByName($city);
  33. return view('admin.cities.edit', [
  34. 'countryId' => $countryId,
  35. 'provinceId' => $provinceId,
  36. 'city' => $city
  37. ]);
  38. }
  39. /**
  40. * Update the city
  41. *
  42. * @param UpdateCityRequest $request
  43. * @param int $countryId
  44. * @param int $provinceId
  45. * @param $city
  46. * @return \Illuminate\Http\RedirectResponse
  47. */
  48. public function update(UpdateCityRequest $request, $countryId, $provinceId, $city)
  49. {
  50. $city = $this->cityRepo->findCityByName($city);
  51. $update = new CityRepository($city);
  52. $update->updateCity($request->only('name'));
  53. return redirect()
  54. ->route('admin.countries.provinces.cities.edit', [$countryId, $provinceId, $city])
  55. ->with('message', 'Update successful');
  56. }
  57. }