diff --git a/TODO.md b/TODO.md index b35473a..8a94fa0 100644 --- a/TODO.md +++ b/TODO.md @@ -6,7 +6,7 @@ - [x] CRUD Banner - [x] CRUD Rekening / Account - [x] CRUD Customer -- [ ] CRUD Lokasi +- [x] CRUD Lokasi - [ ] CRUD Voucher - [ ] Import Voucher - [ ] Deposit Menu (view daftar histori deposit) diff --git a/app/Http/Controllers/Customer/HomeController.php b/app/Http/Controllers/Customer/HomeController.php index 2c60801..ae3b66a 100644 --- a/app/Http/Controllers/Customer/HomeController.php +++ b/app/Http/Controllers/Customer/HomeController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Customer; use App\Http\Controllers\Controller; use App\Models\Banner; use App\Models\Info; +use App\Models\Location; class HomeController extends Controller { @@ -12,10 +13,12 @@ class HomeController extends Controller { $infos = Info::where('is_publish', 1)->orderBy('updated_at', 'desc')->get(); $banners = Banner::orderBy('updated_at', 'desc')->get(); + $locations = Location::get(); return inertia('Home/Index/Index', [ 'infos' => $infos, - 'banners' => $banners + 'banners' => $banners, + 'locations' => $locations ]); } diff --git a/app/Http/Controllers/LocationController.php b/app/Http/Controllers/LocationController.php index 6f75150..f8ed96b 100644 --- a/app/Http/Controllers/LocationController.php +++ b/app/Http/Controllers/LocationController.php @@ -2,9 +2,71 @@ namespace App\Http\Controllers; +use App\Models\Location; use Illuminate\Http\Request; class LocationController extends Controller { - // + public function index() + { + $query = Location::paginate(); + + return inertia('Location/Index', [ + 'query' => $query, + ]); + } + + public function store(Request $request) + { + $request->validate([ + 'name' => 'required|string', + 'description' => 'nullable|string', + 'logo' => 'nullable|image', + ]); + + $logo = null; + if ($request->hasFile('midtrans_logo_file')) { + $file = $request->file('midtrans_logo_file'); + $file->store('uploads', 'public'); + $logo = $file->hashName('uploads'); + } + + Location::create([ + 'name' => $request->name, + 'description' => $request->description, + 'logo' => $logo, + ]); + + session()->flash('message', ['type' => 'success', 'message' => 'Item has beed saved']); + } + + public function update(Request $request, Location $location) + { + $request->validate([ + 'name' => 'required|string', + 'description' => 'nullable|string', + 'logo' => 'nullable|image', + ]); + + if ($request->hasFile('midtrans_logo_file')) { + $file = $request->file('midtrans_logo_file'); + $file->store('uploads', 'public'); + $location->logo = $file->hashName('uploads'); + } + + $location->update([ + 'name' => $request->name, + 'description' => $request->description, + 'logo' => $location->logo, + ]); + + session()->flash('message', ['type' => 'success', 'message' => 'Item has beed updated']); + } + + public function destroy(Location $location) + { + $location->delete(); + + session()->flash('message', ['type' => 'success', 'message' => 'Item has beed deleted']); + } } diff --git a/database/seeders/DummySeeder.php b/database/seeders/DummySeeder.php index 4204bde..0806881 100644 --- a/database/seeders/DummySeeder.php +++ b/database/seeders/DummySeeder.php @@ -5,6 +5,7 @@ namespace Database\Seeders; use App\Models\Account; use App\Models\Banner; use App\Models\Info; +use App\Models\Location; use Illuminate\Database\Seeder; class DummySeeder extends Seeder @@ -19,6 +20,7 @@ class DummySeeder extends Seeder $this->info(); $this->banner(); $this->account(); + $this->location(); } public function info() @@ -57,4 +59,16 @@ class DummySeeder extends Seeder ]); } } + + public function location() + { + $locations = ['Jarbriel.id', 'Shaff.net', 'Weslycamp.net', 'Glory.net', 'Salgo.id', 'Terna.id', 'Kanza.id']; + + foreach ($locations as $location) { + Location::create([ + 'name' => $location, + 'description' => '-' + ]); + } + } } diff --git a/resources/js/Layouts/Partials/routes.js b/resources/js/Layouts/Partials/routes.js index 0dd1444..03c3d75 100644 --- a/resources/js/Layouts/Partials/routes.js +++ b/resources/js/Layouts/Partials/routes.js @@ -8,6 +8,7 @@ import { } from 'react-icons/hi' import { HiBanknotes, + HiMap, HiOutlineGlobeAlt, HiQuestionMarkCircle, HiUserCircle, @@ -46,6 +47,14 @@ export default [ active: 'setting.*', permission: 'view-setting', }, + { + name: 'Lokasi', + show: true, + icon: HiMap, + route: route('location.index'), + active: 'location.*', + permission: 'view-location', + }, { name: 'Front Home', show: true, diff --git a/resources/js/Pages/Home/Index/Index.jsx b/resources/js/Pages/Home/Index/Index.jsx index 8faf39e..ea53d34 100644 --- a/resources/js/Pages/Home/Index/Index.jsx +++ b/resources/js/Pages/Home/Index/Index.jsx @@ -29,7 +29,7 @@ const GuestBanner = () => { ) } -export default function Index({ auth: { user }, infos, banners }) { +export default function Index({ auth: { user }, infos, banners, locations }) { const handleBanner = (banner) => { router.get(route('home.banner', banner)) } @@ -73,27 +73,15 @@ export default function Index({ auth: { user }, infos, banners }) {
+ Name + | ++ Description + | ++ |
---|---|---|
+ {location.name} + | ++ {location.description} + | +
+
+
+
+ Ubah
+
+
+
+
+ Hapus
+
+ |
+