app/Http/Controllers/CompanyController.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(
                'name.required'=>'Name  required',
                'type.required'=>'Type required',
                'website.required'=>'Website required',
                'description.required'=>'description required',
            );
            $validation=app('validator')->make($request->all(),[
                'name'=>'required',
                'type'        => 'required', 
                'website'         => 'required', 
                'description'     => 'required', 
            ],$rules);
            if(!$validation->passes())
            {
                return redirect()->back()->withInput()->withErrors($validation);
            }
            $id=$request->id;
            if(empty($id)){
                return redirect()->route('company');
            }
            $obj=Company::find($id);
            if(empty($obj)){
                $flashArr = array(
                    'msg' => 'Company details dose not exist'  
                );
                $request->Session()->flash('succ_message',$flashArr);
                return redirect()->route('company.edit',['id'=>$id]);
            }        
            $obj->name =$request->name;
            $obj->type =$request->type;
            $obj->website =$request->website;
            $obj->description =$request->description;     
            $res=$obj->save();
            if($res){               
                $flashArr = array(
                    'msg' => 'Company updated successfully' 
                );
                $request->Session()->flash('succ_message',$flashArr);
            }else{
                $flashArr = array(
                    'msg' => 'Company updated failed'  
                );
                $request->Session()->flash('err_message',$flashArr);
            }
        } catch (Exception $e) {
            $flashArr = array(
                'msg' => 'Company updated failed '.$e->getMessage()
            );
            $request->Session()->flash('err_message',$flashArr);
        }
        return redirect()->route('company.edit',['id'=>$id]);
    }
public function update ( Request $ request ) { try { $ rules = array ( 'name.required' => 'Name  required' , 'type.required' => 'Type required' , 'website.required' => 'Website required' , 'description.required' => 'description required' , ) ; $ validation = app ( 'validator' ) -> make ( $ request -> all ( ) , [ 'name' => 'required' , 'type' => 'required' , 'website' => 'required' , 'description' => 'required' , ] , $ rules ) ; if ( ! $ validation -> passes ( ) ) { return redirect ( ) -> back ( ) -> withInput ( ) -> withErrors ( $ validation ) ; } $ id = $ request -> id ; if ( empty ( $ id ) ) { return redirect ( ) -> route ( 'company' ) ; } $ obj = Company :: find ( $ id ) ; if ( empty ( $ obj ) ) { $ flashArr = array ( 'msg' => 'Company details dose not exist' ) ; $ request -> Session ( ) -> flash ( 'succ_message' , $ flashArr ) ; return redirect ( ) -> route ( 'company.edit' , [ 'id' => $ id ] ) ; } $ obj -> name = $ request -> name ; $ obj -> type = $ request -> type ; $ obj -> website = $ request -> website ; $ obj -> description = $ request -> description ; $ res = $ obj -> save ( ) ; if ( $ res ) { $ flashArr = array ( 'msg' => 'Company updated successfully' ) ; $ request -> Session ( ) -> flash ( 'succ_message' , $ flashArr ) ; } else { $ flashArr = array ( 'msg' => 'Company updated failed' ) ; $ request -> Session ( ) -> flash ( 'err_message' , $ flashArr ) ; } } catch ( Exception $ e ) { $ flashArr = array ( 'msg' => 'Company updated failed ' . $ e -> getMessage ( ) ) ; $ request -> Session ( ) -> flash ( 'err_message' , $ flashArr ) ; } return redirect ( ) -> route ( 'company.edit' , [ 'id' => $ id ] ) ; }
Update the specified resource in storage.
Update the specified resource in storage .