app/Http/Controllers/UsersController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request) 
    {  
    if(Auth::user()->role=='Administrador'){
        $fields = [
            'name' => 'required|string|max:100',
            'phone' => 'required|string|max:20',
            'email' => 'required|email',
            'country' => 'required|string|max:40',
            'city' => 'required|string|max:40',
            'establishment_name' => 'required|string|max:100',
            'password' => 'required',
         ];
         $message = ["required" => "El campo :attribute es requerido"];
         $this -> validate($request, $fields, $message);
         if($request->role == "Distribuidor"){
            $userData = request()->except('_token');
        if ($request->hasFile('image')) {
            $userData['image'] = $request->file('image')->store('images','public');
        }
        $userData['password'] = Hash::make($request->input('password'));
        User::insert($userData);  
        }elseif($request->role == "Ferretero"){
            $userData = request()->except('_token');
            if ($request->hasFile('image')) {
                $userData['image'] = $request->file('image')->store('images','public');
            }
            $userData['password'] = Hash::make($request->input('password'));
            User::insert($userData);  
        }else{
            $userData = request()->except(['_token','price_list_id']);
            if ($request->hasFile('image')) {
                $userData['image'] = $request->file('image')->store('images','public');
            }
            $userData['password'] = Hash::make($request->input('password'));
            User::insert($userData);    
        }
       return redirect('/users/create')->with('messageSuccess','Usuario registrado con éxito');
    }
    }
public function store ( Request $ request ) { if ( Auth :: user ( ) -> role == 'Administrador' ) { $ fields = [ 'name' => 'required|string|max:100' , 'phone' => 'required|string|max:20' , 'email' => 'required|email' , 'country' => 'required|string|max:40' , 'city' => 'required|string|max:40' , 'establishment_name' => 'required|string|max:100' , 'password' => 'required' , ] ; $ message = [ " required " => " El campo :attribute es requerido " ] ; $ this -> validate ( $ request , $ fields , $ message ) ; if ( $ request -> role == " Distribuidor " ) { $ userData = request ( ) -> except ( '_token' ) ; if ( $ request -> hasFile ( 'image' ) ) { $ userData [ 'image' ] = $ request -> file ( 'image' ) -> store ( 'images' , 'public' ) ; } $ userData [ 'password' ] = Hash :: make ( $ request -> input ( 'password' ) ) ; User :: insert ( $ userData ) ; } elseif ( $ request -> role == " Ferretero " ) { $ userData = request ( ) -> except ( '_token' ) ; if ( $ request -> hasFile ( 'image' ) ) { $ userData [ 'image' ] = $ request -> file ( 'image' ) -> store ( 'images' , 'public' ) ; } $ userData [ 'password' ] = Hash :: make ( $ request -> input ( 'password' ) ) ; User :: insert ( $ userData ) ; } else { $ userData = request ( ) -> except ( [ '_token' , 'price_list_id' ] ) ; if ( $ request -> hasFile ( 'image' ) ) { $ userData [ 'image' ] = $ request -> file ( 'image' ) -> store ( 'images' , 'public' ) ; } $ userData [ 'password' ] = Hash :: make ( $ request -> input ( 'password' ) ) ; User :: insert ( $ userData ) ; } return redirect ( '/users/create' ) -> with ( 'messageSuccess' , 'Usuario registrado con éxito') ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
//return redirect('users.index',$role='all')->with('message','Usuario registrado con éxito');