<?php

namespace App\Http\Controllers;
use App\Http\Requests\StoreUser as StoreRequest;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use RealRashid\SweetAlert\Facades\Alert;
class AdminAccesController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $utilisateur_admins= DB::table('users')
         ->where('role','=',2)
         ->orderBy('created_at', 'desc')
         ->paginate(150);
        return view('super_admin.liste_compte_admin',compact('utilisateur_admins'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('super_admin.compte_admin');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(StoreRequest $request)
    {
        $police = new User();
        $police->email = $request->input('email');
        $police->name = $request->input('name');
        $police->role = $request->input('role');
        $police->password = Hash::make($request->input('password'));
        $police->save();
        Alert::success('Message',' Admin create successfully');
        return redirect()->route('compte.index')
            ->with('modif','admin enregistrée avec succès.');

    }
    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit(User $utilisateur_admin)
    {
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {



    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $utilisateur_admin = User::find($id);
        $utilisateur_admin->delete();

        return back()->with('info', 'Suppression effecutée avec succès.');
    }
}




/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */


