LogoController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Http\Controllers\Admin\Config\Layout;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\Config;
  6. use App\Models\FileLib;
  7. class LogoController extends Controller
  8. {
  9. private Config $configModel;
  10. public function __construct(Config $config)
  11. {
  12. $this->configModel = $config;
  13. }
  14. /**
  15. * 로고
  16. * @method GET
  17. * @see /admin/config/layout/logo
  18. */
  19. public function index()
  20. {
  21. return view('admin.config.layout.logo', []);
  22. }
  23. /**
  24. * 로고 저장
  25. * @method POST
  26. * @see /admin/config/layout/logo
  27. */
  28. public function store(Request $request, FileLib $fileLib)
  29. {
  30. $rules = [
  31. 'site_favicon' => 'mimes:ico|max:1192',
  32. 'site_logo' => 'mimes:jpg,jpeg,gif,png|max:2192'
  33. ];
  34. $attributes = [
  35. 'site_favicon' => '사이트 파비콘',
  36. 'site_logo' => '사이트 로고',
  37. ];
  38. $this->validate($request, $rules, [], $attributes);
  39. // 파일 저장
  40. $storage = (UPLOAD_PATH_STORAGE . DIRECTORY_SEPARATOR);
  41. $updateData = [];
  42. if($request->hasFile('site_favicon')) {
  43. $siteFavicon = $request->file('site_favicon');
  44. $siteFavicon->store(UPLOAD_PATH_PUBLIC . DIRECTORY_SEPARATOR . UPLOAD_PATH_FAVICON);
  45. $updateData['site_favicon'] = ($storage . UPLOAD_PATH_LOGO . DIRECTORY_SEPARATOR . $siteFavicon->hashName());
  46. }
  47. if($request->hasFile('site_logo')) {
  48. $siteLogo = $request->file('site_logo');
  49. $siteLogo->store(UPLOAD_PATH_PUBLIC . DIRECTORY_SEPARATOR . UPLOAD_PATH_LOGO);
  50. $updateData['site_logo'] = ($storage . UPLOAD_PATH_LOGO . DIRECTORY_SEPARATOR . $siteLogo->hashName());
  51. }
  52. // 파일 삭제
  53. if($request->get('site_favicon_del')) {
  54. $faviconPath = ($request->get('site_favicon_url'));
  55. if(file_exists($faviconPath)) {
  56. unlink($faviconPath);
  57. }
  58. $updateData['site_favicon'] = '';
  59. }
  60. if($request->get('site_logo_del')) {
  61. $logoPath = $request->get('site_logo_url');
  62. if(file_exists($logoPath)) {
  63. unlink($logoPath);
  64. }
  65. $updateData['site_logo'] = '';
  66. }
  67. $this->configModel->save($updateData, $attributes);
  68. $message = '로고 정보가 저장되었습니다.';
  69. return redirect()->route('admin.config.layout.logo.index')->with('message', $message);
  70. }
  71. }