app/Http/Controllers/Admin/StatesController.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 (Gate::denies('manage-system')) {
            return redirect()->route('admin.states.create');
        }
        $validator = Validator::make($request->all(), [
            'name'  => ['required', 'string', 'min:3', 'max:128'],
            'code'  => ['nullable', 'string'],
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            return redirect()->route('admin.states.create');
        }
        $data = $request->all();
        $state = State::create([
            'name'  => $data['name'],
            'code'  => $data['code'],
        ]);
        if($state == NULL) {
            $request->session()->flash('error', 'There is an error creating Province/State!');
            return redirect()->route('admin.states.create');
        }
        $request->session()->flash('success', 'You have modified Province/State!');
        return redirect()->route('admin.states.index');
    }
public function store ( Request $ request ) { if ( Gate :: denies ( 'manage-system' ) ) { return redirect ( ) -> route ( 'admin.states.create' ) ; } $ validator = Validator :: make ( $ request -> all ( ) , [ 'name' => [ 'required' , 'string' , 'min:3' , 'max:128' ] , 'code' => [ 'nullable' , 'string' ] , ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.states.create' ) ; } $ data = $ request -> all ( ) ; $ state = State :: create ( [ 'name' => $ data [ 'name' ] , 'code' => $ data [ 'code' ] , ] ) ; if ( $ state == NULL ) { $ request -> session ( ) -> flash ( 'error' , 'There is an error creating Province/State!' ) ; return redirect ( ) -> route ( 'admin.states.create' ) ; } $ request -> session ( ) -> flash ( 'success' , 'You have modified Province/State!' ) ; return redirect ( ) -> route ( 'admin.states.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .