<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\User;

class UsersController extends Controller
{
    //midelware per demanar que s'estigui registrat
    public function __construct()
    {
        $this->middleware('auth');
    }

    /** Llista usuaris disponiles
     * @return mixed
     */
    public function llistarUsuaris()
    {
        $Users = new User;
        $User = $Users->orderBy('name', 'desc')->get();
        return view('auth.usuaris')->with('User',$User);
    }

    /** Elimina un usuari enviat des de la vista
     * @param Request $request
     * @return mixed
     */
    public function eliminarUsuaris(Request $request)
    {
        $Users = new User;
        $id = $request->input('id_user');
        $Users->eliminarUsuari($id);
        return redirect('/llistarusuaris');
    }
}
