app/Http/Controllers/ViewController.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)
    {
        $id = $request->input("id");
        $name = $request->input("name");
        $color = $request->input("color");
        $resources = [];
        if($request->session()->exists('resources')) {
            $resources = $request->session()->get('resources');
        }
        $idRequerida = 0;
        foreach($resources as $resource ) {
            if($resource['id'] > $idRequerida){
                $idRequerida = $resource['id'];
            }
        }
        $id = $idRequerida + 1;
        $resource = ['id' => $id, 'name' => $name, 'color' => $color];
        if(isset($resources[$id])) {
            return back()->withInput();
        } else {
            $resources[$id] = $resource;
        }
        $request->session()->put('resources', $resources);
        return redirect("resource");
    }
public function store ( Request $ request ) { $ id = $ request -> input ( " id " ) ; $ name = $ request -> input ( " name " ) ; $ color = $ request -> input ( " color " ) ; $ resources = [ ] ; if ( $ request -> session ( ) -> exists ( 'resources' ) ) { $ resources = $ request -> session ( ) -> get ( 'resources' ) ; } $ idRequerida = 0 ; foreach ( $ resources as $ resource ) { if ( $ resource [ 'id' ] > $ idRequerida ) { $ idRequerida = $ resource [ 'id' ] ; } } $ id = $ idRequerida + 1 ; $ resource = [ 'id' => $ id , 'name' => $ name , 'color' => $ color ] ; if ( isset ( $ resources [ $ id ] ) ) { return back ( ) -> withInput ( ) ; } else { $ resources [ $ id ] = $ resource ; } $ request -> session ( ) -> put ( 'resources' , $ resources ) ; return redirect ( " resource " ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .