From c42480e74e9964d9bb78cd8927acaa5e4dab0fb1 Mon Sep 17 00:00:00 2001 From: Nguyen Tan Dung Date: Sun, 10 Dec 2023 23:33:28 +0700 Subject: [PATCH] setting.blade.php --- app/Helpers/Helper.php | 50 +++++++ app/Http/Controllers/Admin/AuthController.php | 12 +- .../Controllers/Admin/HomepageController.php | 3 +- .../Controllers/Admin/OptionController.php | 65 --------- .../Controllers/Admin/SettingController.php | 42 ++++++ .../Controllers/User/HomepageController.php | 3 +- app/Http/Middleware/CheckAdminMiddleware.php | 24 ++++ .../Repositories/Admin/SettingRepository.php | 43 ++++++ app/Http/Requests/SettingRequest.php | 51 +++++++ .../{AuthServices.php => AuthService.php} | 2 +- app/Http/Services/Admin/SettingService.php | 54 +++++++ config/app.php | 15 +- package-lock.json | 128 ++++------------- package.json | 6 +- resources/js/app.ts | 5 + resources/js/guest.ts | 1 + resources/js/setting.js | 135 ++++++++++++++++++ resources/views/admin/auth/login.blade.php | 4 +- resources/views/admin/setting.blade.php | 93 ++++++++++++ .../components/admin/layouts/app.blade.php | 46 ++++-- .../components/admin/layouts/guest.blade.php | 9 -- .../admin/layouts/partials/header.blade.php | 84 +++++++---- .../admin/layouts/partials/sidebar.blade.php | 4 +- .../components/forms/buttons/index.blade.php | 8 ++ .../components/forms/inputs/file.blade.php | 54 +++++++ .../components/forms/inputs/index.blade.php | 4 +- .../views/components/partials/toast.blade.php | 2 +- .../user/layouts/partials/header.blade.php | 4 +- routes/admin.php | 7 + routes/breadcrumbs.php | 5 + vite.config.js | 2 + 31 files changed, 733 insertions(+), 232 deletions(-) delete mode 100644 app/Http/Controllers/Admin/OptionController.php create mode 100644 app/Http/Controllers/Admin/SettingController.php create mode 100644 app/Http/Middleware/CheckAdminMiddleware.php create mode 100644 app/Http/Repositories/Admin/SettingRepository.php create mode 100644 app/Http/Requests/SettingRequest.php rename app/Http/Services/Admin/{AuthServices.php => AuthService.php} (96%) create mode 100644 app/Http/Services/Admin/SettingService.php create mode 100644 resources/js/setting.js create mode 100644 resources/views/admin/setting.blade.php create mode 100644 resources/views/components/forms/buttons/index.blade.php create mode 100644 resources/views/components/forms/inputs/file.blade.php diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index b3d9bbc..d92e60e 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -1 +1,51 @@ getValueByKey($name); + + if ($value == null) { + return $default; + } + + return $value; + } + + if (!function_exists('getNameRouteMain')) { + function getNameRouteMain(): string + { + $arrRouteName = explode('.', request()->route()->getName()); + + $result = $arrRouteName[0]; + if($arrRouteName[0] == 'admin') { + $result = $arrRouteName[1]; + } + + return $result == "index" ? "" : $result; + } + } + + if (!function_exists('getSubtitle')) { + function getSubtitle(): string + { + $result = getNameRouteMain(); + + return $result == "" ? "" : ' - '. ucfirst($result); + } + } + + if (!function_exists('getImageFromStorage')) { + function getImageFromStorage($value, $url): string + { + if ($value == '' || $value == null) { + return asset($url); + } + + return Storage::url($value); + } + } +} diff --git a/app/Http/Controllers/Admin/AuthController.php b/app/Http/Controllers/Admin/AuthController.php index 34f3301..2e34f42 100644 --- a/app/Http/Controllers/Admin/AuthController.php +++ b/app/Http/Controllers/Admin/AuthController.php @@ -4,7 +4,7 @@ use App\Http\Controllers\Controller; use App\Http\Requests\Auth\LoginRequest; -use App\Http\Services\Admin\AuthServices; +use App\Http\Services\Admin\AuthService; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -12,19 +12,19 @@ class AuthController extends Controller { - Protected AuthServices $authServices; + Protected AuthService $authServices; public function __construct() { - $this->authServices = new AuthServices(); + $this->authServices = new AuthService(); } - public function login() : View + public function login(): View { return view('admin.auth.login'); } - public function logout() + public function logout(): RedirectResponse { Auth::logout(); return redirect() @@ -32,7 +32,7 @@ public function logout() ->with('success', trans("Logout Successfully")); } - public function processLogin(LoginRequest $request) + public function processLogin(LoginRequest $request): RedirectResponse { $data = $request->validated(); $remember = $request->has('remember'); diff --git a/app/Http/Controllers/Admin/HomepageController.php b/app/Http/Controllers/Admin/HomepageController.php index a322558..9e29e0a 100644 --- a/app/Http/Controllers/Admin/HomepageController.php +++ b/app/Http/Controllers/Admin/HomepageController.php @@ -3,10 +3,11 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; +use Illuminate\View\View; class HomepageController extends Controller { - public function __invoke() + public function __invoke() : View { return view('admin.index'); } diff --git a/app/Http/Controllers/Admin/OptionController.php b/app/Http/Controllers/Admin/OptionController.php deleted file mode 100644 index 896555e..0000000 --- a/app/Http/Controllers/Admin/OptionController.php +++ /dev/null @@ -1,65 +0,0 @@ -settingService = new SettingService(); + } + /** + * Display a listing of the resource. + */ + public function index(): View + { + return view("admin.setting"); + } + + /** + * Save the form for editing the specified resource. + */ + public function save(SettingRequest $request) + { + $data = $request->validated(); + $result = $this->settingService->save($data); + + if ($result) + return redirect() + ->route("admin.index") + ->with("success", trans("Update Successfully")); + return redirect()->back()->withErrors("Update Failed"); + } +} diff --git a/app/Http/Controllers/User/HomepageController.php b/app/Http/Controllers/User/HomepageController.php index 760579d..f486f4d 100644 --- a/app/Http/Controllers/User/HomepageController.php +++ b/app/Http/Controllers/User/HomepageController.php @@ -3,10 +3,11 @@ namespace App\Http\Controllers\User; use App\Http\Controllers\Controller; +use Illuminate\View\View; class HomepageController extends Controller { - public function __invoke() + public function __invoke(): View { return view('index'); } diff --git a/app/Http/Middleware/CheckAdminMiddleware.php b/app/Http/Middleware/CheckAdminMiddleware.php new file mode 100644 index 0000000..a673ba8 --- /dev/null +++ b/app/Http/Middleware/CheckAdminMiddleware.php @@ -0,0 +1,24 @@ +level !== 4) + return redirect()->route('admin.login')->withErrors('You must login account admin to continue'); + + return $next($request); + } +} diff --git a/app/Http/Repositories/Admin/SettingRepository.php b/app/Http/Repositories/Admin/SettingRepository.php new file mode 100644 index 0000000..741cc88 --- /dev/null +++ b/app/Http/Repositories/Admin/SettingRepository.php @@ -0,0 +1,43 @@ +option = new Option(); + } + + /** + * @param string $key + * @return Builder|Option + */ + public function getSetting(string $key): Builder|Option + { + return $this->option::query() + ->where('name', $key)->firstOrFail(); + } + + public function save(string $key, string $value = null): bool + { + try { + $option = $this->option::query() + ->updateOrCreate([ + "name" => $key + ], [ + "value" => $value + ]); + + $option->save(); + return true; + } catch (\Exception $e) { + return false; + } + } +} diff --git a/app/Http/Requests/SettingRequest.php b/app/Http/Requests/SettingRequest.php new file mode 100644 index 0000000..d8fb573 --- /dev/null +++ b/app/Http/Requests/SettingRequest.php @@ -0,0 +1,51 @@ +level == 4; + } + + /** + * Get the validation rules that apply to the request. + * + * @return array|string> + */ + public function rules(): array + { + return [ + "site_name" => ["required", "string", "min:4"], + "slogan" => ["required", "string", "min:4"], + "logo_light" => ["image", "mimes:jpeg,png,jpg", "max:3072", "nullable"], + "logo_dark" => ["image", "mimes:jpeg,png,jpg", "max:3072", "nullable"], + "site_address" => ["required", "string", "min:4"], + "email" => ["required", "email"], + "phone" => ["required", "string", "min:5", "max:15"], + "lat" => ["required", "numeric"], + "lng" => ["required", "numeric"], + ]; + } + + public function messages(): array + { + return [ + "image" => trans("Invalid image"), + "mimes:jpeg,png,jpg" => trans("uploaded image must be png, jpg, jpeg file"), + "max:3072" => trans("Images must be under 3072 kb"), + "email" => trans("Unknown error please try again"), + "string" => trans("Unknown error please try again"), + "min:4" => trans("Fields must be more than 4 characters"), + "phone.max:15" => trans("Fields must be less than 32 characters"), + "numeric" => trans("Unknown error please try again"), + ]; + } +} diff --git a/app/Http/Services/Admin/AuthServices.php b/app/Http/Services/Admin/AuthService.php similarity index 96% rename from app/Http/Services/Admin/AuthServices.php rename to app/Http/Services/Admin/AuthService.php index 9491581..ec73b8a 100644 --- a/app/Http/Services/Admin/AuthServices.php +++ b/app/Http/Services/Admin/AuthService.php @@ -5,7 +5,7 @@ use App\Models\User; use Illuminate\Support\Facades\Auth; -class AuthServices { +class AuthService { public function login(string $email, string $password, bool $remember): bool { diff --git a/app/Http/Services/Admin/SettingService.php b/app/Http/Services/Admin/SettingService.php new file mode 100644 index 0000000..f3ca1eb --- /dev/null +++ b/app/Http/Services/Admin/SettingService.php @@ -0,0 +1,54 @@ +settingRepository = new SettingRepository(); + } + + public function getValueByKey(string $key): ?string + { + try { + $option = $this->settingRepository->getSetting($key); + + $value = $option->value; + } catch (\Exception $e) { + $value = null; + } + + return $value; + } + + public function save(array $data): bool + { + try { + foreach ($data as $key => $value) { + if(str_contains($key, 'logo')) { + if (option($key) != null) { + Storage::disk('public')->delete(option('site_logo')); + } + + $fileLogo = $value; + $nameFileLogo = $key . '_' . Str::random(10) . '.' . $fileLogo->extension(); + $filePathLogo = $fileLogo->storeAs('images', $nameFileLogo, 'public'); + + $value = $filePathLogo; + } + $this->settingRepository->save($key, $value); + } + return true; + } catch (\Exception $e) { + return false; + } + } +} diff --git a/config/app.php b/config/app.php index 004b027..69bcf26 100644 --- a/config/app.php +++ b/config/app.php @@ -16,7 +16,7 @@ | */ - 'name' => env('APP_NAME', 'Laravel'), + 'name' => env('APP_NAME', 'Dũng Phát'), /* |-------------------------------------------------------------------------- @@ -126,6 +126,19 @@ 'cipher' => 'AES-256-CBC', + /* + |-------------------------------------------------------------------------- + | API Keys + |-------------------------------------------------------------------------- + | + | This section stores secret API keys used by your application. These keys + | should not be shared publicly and should be stored securely. + | + */ + 'api_keys' => [ + 'google_maps' => env('GOOGLE_MAPS_API_KEY'), + ], + /* |-------------------------------------------------------------------------- | Maintenance Mode Driver diff --git a/package-lock.json b/package-lock.json index fe29a86..f12bf72 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,15 +5,17 @@ "packages": { "": { "dependencies": { + "@googlemaps/js-api-loader": "^1.16.2", + "@types/google.maps": "^3.54.10", "lucide": "^0.293.0", "preline": "^2.0.2", "resize-observer-polyfill": "^1.5.1", "simplebar": "^6.2.5", - "swiper": "^11.0.5" + "swiper": "^11.0.5", + "toastify-js": "^1.12.0" }, "devDependencies": { "autoprefixer": "^10.4.16", - "axios": "^1.6.1", "laravel-vite-plugin": "^0.8.0", "postcss": "^8.4.31", "tailwindcss": "^3.3.5", @@ -385,6 +387,14 @@ "node": ">=12" } }, + "node_modules/@googlemaps/js-api-loader": { + "version": "1.16.2", + "resolved": "https://registry.npmjs.org/@googlemaps/js-api-loader/-/js-api-loader-1.16.2.tgz", + "integrity": "sha512-psGw5u0QM6humao48Hn4lrChOM2/rA43ZCm3tKK9qQsEj1/VzqkCqnvGfEOshDbBQflydfaRovbKwZMF4AyqbA==", + "dependencies": { + "fast-deep-equal": "^3.1.3" + } + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz", @@ -477,6 +487,11 @@ "url": "https://opencollective.com/popperjs" } }, + "node_modules/@types/google.maps": { + "version": "3.54.10", + "resolved": "https://registry.npmjs.org/@types/google.maps/-/google.maps-3.54.10.tgz", + "integrity": "sha512-N6gwM01mKhooXaw+IKbUH7wJcIJCn8U60VoaVvom5EiQjmfgevhQ+0+/r17beXW5j8ad2x+WPr0iyOUodCw4/w==" + }, "node_modules/@types/lodash": { "version": "4.14.202", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.202.tgz", @@ -515,12 +530,6 @@ "integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==", "dev": true }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true - }, "node_modules/autoprefixer": { "version": "10.4.16", "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.16.tgz", @@ -558,17 +567,6 @@ "postcss": "^8.1.0" } }, - "node_modules/axios": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", - "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", - "dev": true, - "dependencies": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -752,18 +750,6 @@ "simple-swizzle": "^0.2.2" } }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/commander": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", @@ -791,15 +777,6 @@ "node": ">=4" } }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true, - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/didyoumean": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz", @@ -864,6 +841,11 @@ "node": ">=6" } }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" + }, "node_modules/fast-glob": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", @@ -922,40 +904,6 @@ "flat": "cli.js" } }, - "node_modules/follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", - "dev": true, - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, - "node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/fraction.js": { "version": "4.3.7", "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.3.7.tgz", @@ -1201,27 +1149,6 @@ "node": ">=8.6" } }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "dev": true, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dev": true, - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -1519,12 +1446,6 @@ "@popperjs/core": "^2.11.2" } }, - "node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", - "dev": true - }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -1797,6 +1718,11 @@ "node": ">=8.0" } }, + "node_modules/toastify-js": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/toastify-js/-/toastify-js-1.12.0.tgz", + "integrity": "sha512-HeMHCO9yLPvP9k0apGSdPUWrUbLnxUKNFzgUoZp1PHCLploIX/4DSQ7V8H25ef+h4iO9n0he7ImfcndnN6nDrQ==" + }, "node_modules/ts-interface-checker": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", diff --git a/package.json b/package.json index 2938097..40006a2 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ }, "devDependencies": { "autoprefixer": "^10.4.16", - "axios": "^1.6.1", "laravel-vite-plugin": "^0.8.0", "postcss": "^8.4.31", "tailwindcss": "^3.3.5", @@ -15,10 +14,13 @@ "vite": "^4.0.0" }, "dependencies": { + "@googlemaps/js-api-loader": "^1.16.2", + "@types/google.maps": "^3.54.10", "lucide": "^0.293.0", "preline": "^2.0.2", "resize-observer-polyfill": "^1.5.1", "simplebar": "^6.2.5", - "swiper": "^11.0.5" + "swiper": "^11.0.5", + "toastify-js": "^1.12.0" } } diff --git a/resources/js/app.ts b/resources/js/app.ts index 8266233..b45cf5e 100644 --- a/resources/js/app.ts +++ b/resources/js/app.ts @@ -3,3 +3,8 @@ import 'preline'; // import css import '../css/app.css'; + +import Toastify from 'toastify-js/src/toastify.js'; +import "toastify-js/src/toastify.css" + +window.Toastify = Toastify; diff --git a/resources/js/guest.ts b/resources/js/guest.ts index d4ce736..6ccf07e 100644 --- a/resources/js/guest.ts +++ b/resources/js/guest.ts @@ -27,6 +27,7 @@ document.querySelectorAll("[data-x-password]").forEach(password => { } }); }) + const setProperty = (object: object, property: string | symbol, value: any) => { if (property in object) { Object.defineProperty(object, property, { diff --git a/resources/js/setting.js b/resources/js/setting.js new file mode 100644 index 0000000..7a2e80e --- /dev/null +++ b/resources/js/setting.js @@ -0,0 +1,135 @@ +//region Google Maps +import {Loader} from "@googlemaps/js-api-loader" + +const apiKeyGoogleMap = import.meta.env.VITE_GOOGLE_MAPS_API_KEY; + +const loader = new Loader({ + apiKey: apiKeyGoogleMap, version: "weekly", + libraries: ["places", "marker"], +}); + +let mapConfirm = false; + +document.addEventListener("DOMContentLoaded", () => { + const inputSearch = document.getElementById("address"); + + let valLat = document.getElementById("lat").value; + let valLng = document.getElementById("lng").value; + let lat, lng; + + if (valLat.length > 0) { + lat = valLat; + } else { + lat = 10.800664; + } + + if (valLng.length > 0) { + lng = valLng; + } else { + lng = 106.712588; + } + + if (lat.length > 0 && lng.length > 0) { + inputSearch.style.border = "1px solid green"; + mapConfirm = true; + } + loader.load().then(() => { + + const mapLatLng = new google.maps.LatLng(lat, lng); + + const map = new google.maps.Map(document.getElementById("map"), { + center: mapLatLng, zoom: 18, mapTypeControl: false, + }); + + const marker = new google.maps.Marker({ + position: mapLatLng, + map: map + }) + + inputSearch.addEventListener("focus", () => { + const addressAutoComplete = new google.maps.places.Autocomplete(inputSearch); + addressAutoComplete.bindTo("bounds", map); + google.maps.event.addListener(addressAutoComplete, "place_changed", () => { + let placeObj = addressAutoComplete.getPlace(); + marker.setPosition(placeObj.geometry.location); + map.setCenter(placeObj.geometry.location); + document.getElementById("lat").value = placeObj.geometry.location.lat(); + document.getElementById("lng").value = placeObj.geometry.location.lng(); + + inputSearch.style.border = "1px solid green"; + mapConfirm = true; + }); + }); + }); +}); +//endregion + +//region Validate +let error = ""; + +const form = document.getElementById("form-setting"); + +const validateEmail = (email) => /\S+@\S+\.\S+/.test(email); + +const validate = () => { + error = ""; + + const inpEmail = document.getElementById("email"); + const email = inpEmail.value; + + const inpPhone = document.getElementById("phone"); + const phone = inpPhone.value; + + let isError = false; + if (!mapConfirm) { + error += " Please choose a address on map"; + isError = true; + } + + if (email.length === 0) { + error += "; Please enter a email address"; + + inpEmail.style.border = "1px solid red"; + inpEmail.style.color = "red"; + + isError = true; + } else if (!validateEmail(email)) { + error += "; Please enter a proper email"; + + inpEmail.style.border = "1px solid red"; + inpEmail.style.color = "red"; + + isError = true; + } + + if (phone.length === 0) { + error += "; Please enter a phone number"; + + inpPhone.style.border = "1px solid red"; + inpPhone.style.color = "red"; + + isError = true; + } else if (phone.length < 6 || phone.length > 15) { + console.log(phone.length); + error += "; Please enter a proper phone number"; + + inpPhone.style.border = "1px solid red"; + inpPhone.style.color = "red"; + + isError = true; + } + + return isError; +}; + +form.addEventListener("submit", (e) => { + e.preventDefault(); + + if (validate()) { + document.getElementById("error-message").innerText = error; + } else { + form.submit(); + } +}); +//endregion + diff --git a/resources/views/admin/auth/login.blade.php b/resources/views/admin/auth/login.blade.php index 240faaf..99950f3 100644 --- a/resources/views/admin/auth/login.blade.php +++ b/resources/views/admin/auth/login.blade.php @@ -5,8 +5,8 @@
- logo - + logo +
diff --git a/resources/views/admin/setting.blade.php b/resources/views/admin/setting.blade.php new file mode 100644 index 0000000..c777d62 --- /dev/null +++ b/resources/views/admin/setting.blade.php @@ -0,0 +1,93 @@ + +
+
+ +
+

+ {{ __("Settings") }} +

+ + + {{ Breadcrumbs::render('admin.setting') }} +
+
+
+

{{ __("Information Website") }}

+ +
+ +
+ @csrf +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +

{{ __("The field address turns green to confirm") }}

+
+ + + @push("css") + + @endpush +
+
+ +
+
+ +
+
+ +
+
+ {{ __("Save Changes") }} +
+
+
+
+ +
+

+
+
+
+
+
+ @push("js") + @vite("resources/js/setting.js") + @endpush +
diff --git a/resources/views/components/admin/layouts/app.blade.php b/resources/views/components/admin/layouts/app.blade.php index 7685024..ef66e81 100644 --- a/resources/views/components/admin/layouts/app.blade.php +++ b/resources/views/components/admin/layouts/app.blade.php @@ -1,11 +1,11 @@ - - Dũng Phát - Nhà Hàng Số 1 VN + + {{ option("site_name", config("app.name")) . getSubtitle() }} - - + + @@ -37,20 +37,48 @@ - + - + - + {{ $slot }} - + - + @stack("js") + + diff --git a/resources/views/components/admin/layouts/guest.blade.php b/resources/views/components/admin/layouts/guest.blade.php index 0a5aed9..1635ff2 100644 --- a/resources/views/components/admin/layouts/guest.blade.php +++ b/resources/views/components/admin/layouts/guest.blade.php @@ -25,15 +25,6 @@
- @foreach ($errors->all() as $error) - - @endforeach - - @if (session()->has('success')) - - @endif
- - diff --git a/resources/views/components/admin/layouts/partials/header.blade.php b/resources/views/components/admin/layouts/partials/header.blade.php index fd12b0b..82429a3 100644 --- a/resources/views/components/admin/layouts/partials/header.blade.php +++ b/resources/views/components/admin/layouts/partials/header.blade.php @@ -3,7 +3,8 @@