<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;


class UserController extends Controller
{
    public function index()
    {
        $users = User::all();
        $totalUsers = $users->count();
        return view('users.user.index', compact('users', 'totalUsers'));
    }

    public function getUsers()
    {
        $users = User::select(['id', 'name', 'email', 'email_verified_at', 'created_at'])->get();
        return response()->json(['data' => $users]);
    }

    public function show($id)
    {
        $user = User::findOrFail($id);
        return view('users.user.show', compact('user'));
    }

    public function destroy($id)
    {
        $user = User::findOrFail($id);
        $user->delete();

        return redirect()->route('users.user.index')->with('success', 'User deleted successfully.');
    }
}
