app/Http/Controllers/CompanyController.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)
    {
        try {       
             $rules = array(
                'name.required'=>'Name  required',
                'type.required'=>'Type required',
                'website.required'=>'Website required',
                'description.required'=>'description required',
                'unique'=>'This company is already registerd with us,Please try another',
            );
            $validation=app('validator')->make($request->all(),[
                'name'        => 'required|unique:tbl_company,name', 
                'type'        => 'required', 
                'website'         => 'required', 
                'description'     => 'required', 
            ],$rules);
            if(!$validation->passes())
            {
                return redirect()->back()->withInput()->withErrors($validation);
            }
            $obj=new Company;
            $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 created successfully' 
                );
                $request->Session()->flash('succ_message',$flashArr);
            }else{
                $flashArr = array(
                    'msg' => 'Company created failed'  
                );
                $request->Session()->flash('err_message',$flashArr);
            }
        } catch (Exception $e) {
             $flashArr = array(
                'msg' => 'Company created failed '.$e->getMessage()
            );
            $request->Session()->flash('err_message',$flashArr);
        }
        return redirect()->route('company');
    }
public function store ( Request $ request ) { try { $ rules = array ( 'name.required' => 'Name  required' , 'type.required' => 'Type required' , 'website.required' => 'Website required' , 'description.required' => 'description required' , 'unique' => 'This company is already registerd with us,Please try another' , ) ; $ validation = app ( 'validator' ) -> make ( $ request -> all ( ) , [ 'name' => 'required|unique:tbl_company,name' , 'type' => 'required' , 'website' => 'required' , 'description' => 'required' , ] , $ rules ) ; if ( ! $ validation -> passes ( ) ) { return redirect ( ) -> back ( ) -> withInput ( ) -> withErrors ( $ validation ) ; } $ obj = new Company ; $ 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 created successfully' ) ; $ request -> Session ( ) -> flash ( 'succ_message' , $ flashArr ) ; } else { $ flashArr = array ( 'msg' => 'Company created failed' ) ; $ request -> Session ( ) -> flash ( 'err_message' , $ flashArr ) ; } } catch ( Exception $ e ) { $ flashArr = array ( 'msg' => 'Company created failed ' . $ e -> getMessage ( ) ) ; $ request -> Session ( ) -> flash ( 'err_message' , $ flashArr ) ; } return redirect ( ) -> route ( 'company' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .