with(['owner:id,name', 'agent:id,name'])->orderBy('name'); if ($search = $request->query('search')) { $query->where('name', 'like', "%{$search}%"); } if ($type = $request->query('type')) { $query->where('type', $type); } $types = Store::query()->select('type')->distinct()->orderBy('type')->pluck('type'); return view('admin.stores.index', [ 'stores' => $query->paginate(12)->withQueryString(), 'types' => $types, 'currentSearch' => $search, 'currentType' => $type, ]); } /** * Show the store creation form with the 3D position picker. */ public function create(): View { return view('admin.stores.form', [ 'store' => new Store(['is_open' => true, 'pos_x' => 0, 'pos_y' => 0, 'pos_z' => 0, 'width' => 8, 'height' => 6, 'depth' => 8]), 'owners' => User::query()->orderBy('name')->get(['id', 'name', 'email']), 'agents' => AiAgent::query()->orderBy('name')->get(['id', 'name', 'type']), 'isEdit' => false, ]); } /** * Persist a newly created store. */ public function store(StoreRequest $request): RedirectResponse { $store = Store::create($request->validated()); return redirect() ->route('admin.stores.edit', $store) ->with('status', __('admin.stores.created')); } /** * Show the store edit form pre-filled with the current 3D placement. */ public function edit(Store $store): View { return view('admin.stores.form', [ 'store' => $store, 'owners' => User::query()->orderBy('name')->get(['id', 'name', 'email']), 'agents' => AiAgent::query()->orderBy('name')->get(['id', 'name', 'type']), 'isEdit' => true, ]); } /** * Update an existing store. */ public function update(StoreRequest $request, Store $store): RedirectResponse { $store->update($request->validated()); return redirect() ->route('admin.stores.index') ->with('status', __('admin.stores.updated')); } /** * Delete a store from the city registry. */ public function destroy(Store $store): RedirectResponse { $store->delete(); return redirect() ->route('admin.stores.index') ->with('status', __('stores.deleted')); } }