app/Http/Controllers/UserController.php
/**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
  {
      $this->validate($request,[
        'primerNombre' => 'required|string|max:50|regex:/^([a-zA-ZñÑáéíóúÁÉÍÓÚ_-])+((\s*)+([a-zA-ZñÑáéíóúÁÉÍÓÚ_-]*)*)+$/',
        'segundoNombre' => 'required|string|max:50|regex:/^([a-zA-ZñÑáéíóúÁÉÍÓÚ_-])+((\s*)+([a-zA-ZñÑáéíóúÁÉÍÓÚ_-]*)*)+$/',
        'primerApellido' => 'required|string|max:50|regex:/^([a-zA-ZñÑáéíóúÁÉÍÓÚ_-])+((\s*)+([a-zA-ZñÑáéíóúÁÉÍÓÚ_-]*)*)+$/',
        'segundoApellido' => 'required|string|max:50|regex:/^([a-zA-ZñÑáéíóúÁÉÍÓÚ_-])+((\s*)+([a-zA-ZñÑáéíóúÁÉÍÓÚ_-]*)*)+$/',
        'direccion'=>'string|max:100',
      ]);
      try{
        $user=User::findOrFail($id);
        $user->primerNombre=$request->primerNombre;
        $user->segundoNombre=$request->segundoNombre;
        $user->primerApellido=$request->primerApellido;
        $user->segundoApellido=$request->segundoApellido;
        $user->save();
        $user->roles()->sync($request->get('role'));
      return redirect()->action('UserController@index')->with('msj','#');
      }catch(Exception $e){
        return back()->with('msj2','Usuario no editado,revise los datos proporcionados');
      }
  }
public function update ( Request $ request , $ id ) { $ this -> validate ( $ request , [ 'primerNombre' => 'required|string|max:50|regex:/^([a-zA-ZñÑáéíóúÁÉÍÓÚ_-])+((\s*)+([a-zA-ZñÑáéíóúÁÉÍÓÚ_-]*)*)+$/', 'segundoNombre' => 'required|string|max:50|regex:/^([a-zA-ZñÑáéíóúÁÉÍÓÚ_-])+((\s*)+([a-zA-ZñÑáéíóúÁÉÍÓÚ_-]*)*)+$/', 'primerApellido' => 'required|string|max:50|regex:/^([a-zA-ZñÑáéíóúÁÉÍÓÚ_-])+((\s*)+([a-zA-ZñÑáéíóúÁÉÍÓÚ_-]*)*)+$/', 'segundoApellido' => 'required|string|max:50|regex:/^([a-zA-ZñÑáéíóúÁÉÍÓÚ_-])+((\s*)+([a-zA-ZñÑáéíóúÁÉÍÓÚ_-]*)*)+$/', 'direccion' => 'string|max:100' , ] ) ; try { $ user = User :: findOrFail ( $ id ) ; $ user -> primerNombre = $ request -> primerNombre ; $ user -> segundoNombre = $ request -> segundoNombre ; $ user -> primerApellido = $ request -> primerApellido ; $ user -> segundoApellido = $ request -> segundoApellido ; $ user -> save ( ) ; $ user -> roles ( ) -> sync ( $ request -> get ( 'role' ) ) ; return redirect ( ) -> action ( 'UserController@index' ) -> with ( 'msj' , '#' ) ; } catch ( Exception $ e ) { return back ( ) -> with ( 'msj2' , 'Usuario no editado,revise los datos proporcionados' ) ; } }
Update the specified resource in storage.
Update the specified resource in storage .