app/Http/Controllers/EmployeController.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)
    {
        try {       
            $rules = array(
                'company_id.required'=>'Company  required',
                'first_name.required'=>'Firstname required',
                'last_name.required'=>'Lastname required',
                'email_address.required'=>'Email required',
                'position.required'=>'Position required',
                'city.required'=>'City required',
                'country.required'=>'Country required',
                'status.required'=>'Status required',
            );
            $validation=app('validator')->make($request->all(),[
                'company_id'        => 'required', 
                'first_name'        => 'required', 
                'last_name'         => 'required', 
                'email_address'     => 'required', 
                'position'          => 'required', 
                'city'              => 'required', 
                'country'           => 'required', 
                'status'            => 'required', 
            ],$rules);
            if(!$validation->passes())
            {
                return redirect()->back()->withInput()->withErrors($validation);
            }
            $id=$request->id;
            if(empty($id)){
                return redirect()->route('employe');
            }
            $obj=Employe::find($id);
            if(empty($obj)){
                $flashArr = array(
                    'msg' => 'Employe details dose not exist'  
                );
                $request->Session()->flash('succ_message',$flashArr);
                return redirect()->route('employe.edit',['id'=>$id]);
            }        
            $obj->company_id =$request->company_id;
            $obj->first_name =$request->first_name;
            $obj->last_name =$request->last_name;
            $obj->email_address =$request->email_address;
            $obj->position =$request->position;
            $obj->city =$request->city;
            $obj->country =$request->country;
            $obj->status =$request->status;               
            $res=$obj->save();
            if($res){               
                $flashArr = array(
                    'msg' => 'Employe updated successfully' 
                );
                $request->Session()->flash('succ_message',$flashArr);
            }else{
                $flashArr = array(
                    'msg' => 'Employe updated failed'  
                );
                $request->Session()->flash('err_message',$flashArr);
            }
        } catch (Exception $e) {
            $flashArr = array(
                'msg' => 'Employe updated failed '.$e->getMessage()
            );
            $request->Session()->flash('err_message',$flashArr);
        }
        return redirect()->route('employe.edit',['id'=>$id]);
    }
public function update ( Request $ request ) { try { $ rules = array ( 'company_id.required' => 'Company  required' , 'first_name.required' => 'Firstname required' , 'last_name.required' => 'Lastname required' , 'email_address.required' => 'Email required' , 'position.required' => 'Position required' , 'city.required' => 'City required' , 'country.required' => 'Country required' , 'status.required' => 'Status required' , ) ; $ validation = app ( 'validator' ) -> make ( $ request -> all ( ) , [ 'company_id' => 'required' , 'first_name' => 'required' , 'last_name' => 'required' , 'email_address' => 'required' , 'position' => 'required' , 'city' => 'required' , 'country' => 'required' , 'status' => 'required' , ] , $ rules ) ; if ( ! $ validation -> passes ( ) ) { return redirect ( ) -> back ( ) -> withInput ( ) -> withErrors ( $ validation ) ; } $ id = $ request -> id ; if ( empty ( $ id ) ) { return redirect ( ) -> route ( 'employe' ) ; } $ obj = Employe :: find ( $ id ) ; if ( empty ( $ obj ) ) { $ flashArr = array ( 'msg' => 'Employe details dose not exist' ) ; $ request -> Session ( ) -> flash ( 'succ_message' , $ flashArr ) ; return redirect ( ) -> route ( 'employe.edit' , [ 'id' => $ id ] ) ; } $ obj -> company_id = $ request -> company_id ; $ obj -> first_name = $ request -> first_name ; $ obj -> last_name = $ request -> last_name ; $ obj -> email_address = $ request -> email_address ; $ obj -> position = $ request -> position ; $ obj -> city = $ request -> city ; $ obj -> country = $ request -> country ; $ obj -> status = $ request -> status ; $ res = $ obj -> save ( ) ; if ( $ res ) { $ flashArr = array ( 'msg' => 'Employe updated successfully' ) ; $ request -> Session ( ) -> flash ( 'succ_message' , $ flashArr ) ; } else { $ flashArr = array ( 'msg' => 'Employe updated failed' ) ; $ request -> Session ( ) -> flash ( 'err_message' , $ flashArr ) ; } } catch ( Exception $ e ) { $ flashArr = array ( 'msg' => 'Employe updated failed ' . $ e -> getMessage ( ) ) ; $ request -> Session ( ) -> flash ( 'err_message' , $ flashArr ) ; } return redirect ( ) -> route ( 'employe.edit' , [ 'id' => $ id ] ) ; }
Update the specified resource in storage.
Update the specified resource in storage .