count(); $ussdCount = ShortCode::where('code_type', 'ussd')->count(); $voiceCount = ShortCode::where('code_type', 'voice')->count(); $countries = Country::orderBy('en_short_name', 'asc')->get(); // dd($countries); // Dropdown options $clients = Client::orderBy('name', 'asc')->get(); $networkOperators = NetworkOperator::orderBy('name', 'asc')->get(); $query = ShortCode::query(); // Search Filter if ($request->filled('search')) { $search = $request->search; $query->where(function($q) use ($search) { $q->where('shortcode', 'like', "%{$search}%") ->orWhere('name', 'like', "%{$search}%") ->orWhere('toll_free', 'like', "%{$search}%") ->orWhere('country', 'like', "%{$search}%") ->orWhere('network', 'like', "%{$search}%") ->orWhere('code_type', 'like', "%{$search}%"); }); } // Status Filter if ($request->filled('status')) { $query->where('status', $request->status); } // Execute query with pagination (Fixed variable name from $senderIds to $shortcodes) $shortcodes = $query->orderBy('created_at', 'desc')->paginate(10); $shortcodes->appends($request->query()); $data = [ 'page_title' => 'Short Codes Management', 'totalCount' => $totalCount, 'smsCount' => $smsCount, 'ussdCount' => $ussdCount, 'voiceCount' => $voiceCount, 'shortcodes' => $shortcodes, 'clients' => $clients, 'countries' => $countries, 'networkOperators' => $networkOperators, ]; return view('shortcodes.index', $data); } public function store(Request $request) { $validated = $request->validate([ 'client_id' => 'nullable|integer', 'name' => 'nullable|string|max:192', 'shortcode' => 'required|string|max:20', 'code_type' => 'nullable|string|max:15', 'toll_free' => 'nullable|string|max:10', 'monthly_fee' => 'nullable|numeric', 'country' => 'nullable|string|max:45', 'network' => 'nullable|string|max:45', 'status' => 'nullable|string|max:15', 'launch_date' => 'nullable|date', 'expiry_date' => 'nullable|date', 'remarks' => 'nullable|string|max:250', ]); ShortCode::create($validated); return response()->json(['success' => true, 'message' => 'Short code created successfully!']); } public function update(Request $request, $id) { $shortcode = ShortCode::findOrFail($id); $validated = $request->validate([ 'client_id' => 'nullable|integer', 'name' => 'nullable|string|max:192', 'shortcode' => 'required|string|max:20', 'code_type' => 'nullable|string|max:15', 'toll_free' => 'nullable|string|max:10', 'monthly_fee' => 'nullable|numeric', 'country' => 'nullable|string|max:45', 'network' => 'nullable|string|max:45', 'status' => 'nullable|string|max:15', 'launch_date' => 'nullable|date', 'expiry_date' => 'nullable|date', 'remarks' => 'nullable|string|max:250', ]); $validated['last_updated_by'] = auth()->id(); $shortcode->update($validated); return response()->json(['success' => true, 'message' => 'Short code updated successfully!']); } public function destroy($id) { $shortcode = ShortCode::findOrFail($id); $shortcode->delete(); return redirect()->route('shortcodes.index')->with('success', 'Short code deleted successfully.'); } }