<?php

namespace App\Http\Controllers;
use Validator;
use Illuminate\Http\Request;
use App\Models\Roles;
class RolController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    public function listrols()
    {
           $rol=Roles::select('roles.*')->withCasts([
            'view_t_documents' => 'boolean',
            'view_t_d_photo'=>'boolean',
            'view_t_d_maps'=>'boolean',
            'view_t_d_dowloand'=>'boolean',
            'view_t_users'=>'boolean',
        ])->get();
        return response()->json($rol);
    }
    public function updaterol(Request $request){
        $rules = [
            'id_rol'=>'required',
            'nombre'=>'',
            'image'=>''
        ];
        $input     = $request->only('id_rol');
        $validator = Validator::make($input, $rules);
        if ($validator->fails()) {
            return response()->json(['success' => false, 'error' => $validator->messages()]);
        }
        // $direccion=$request->direccion;
        // $id_usuario=$request->id_usuario;
        $rol = Roles::find($request->id_rol);
        if($rol){
            $rol->name = $request->nombre;
            $rol->view_t_d_photo = $request->image;
            $resultado = $rol->save();
            return response()->json(['success' => $resultado]);
        }else{
            return response()->json(['success' => false]);
        }
    }
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * 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($id)
    {
        //
    }

    /**
     * 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)
    {
        //
    }
}