app/Http/Controllers/TeamsController.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, $id )
    {
        $team_name        = $request->input( 'teamName', false );
        $team_logo        = $request->input( 'teamLogo', false );
        $players_to_add   = $request->input( 'freeAgents', false );
        $player_to_remove = $request->input( 'playerIdToRemove', false );
        $team = Team::find( $id );
        if ( $team_name ) {
            $team->team_name = $team_name;
        }
        if ( $team_logo ) {
            $team->team_logo = $team_logo;
        }
        if ( $team->save() ) {
            if ( $players_to_add ) {
                foreach ( $players_to_add as $player_id ) {
                    $team->players()->attach( $player_id );
                }
            }
            if ( $player_to_remove ) {
                $team->players()->detach( $player_to_remove );
            }
        }
        return redirect( "/project-1/teams/$team->id" );
    }
public function update ( Request $ request , $ id ) { $ team_name = $ request -> input ( 'teamName' , false ) ; $ team_logo = $ request -> input ( 'teamLogo' , false ) ; $ players_to_add = $ request -> input ( 'freeAgents' , false ) ; $ player_to_remove = $ request -> input ( 'playerIdToRemove' , false ) ; $ team = Team :: find ( $ id ) ; if ( $ team_name ) { $ team -> team_name = $ team_name ; } if ( $ team_logo ) { $ team -> team_logo = $ team_logo ; } if ( $ team -> save ( ) ) { if ( $ players_to_add ) { foreach ( $ players_to_add as $ player_id ) { $ team -> players ( ) -> attach ( $ player_id ) ; } } if ( $ player_to_remove ) { $ team -> players ( ) -> detach ( $ player_to_remove ) ; } } return redirect ( " /project-1/teams/ $ team -> id " ) ; }
Update the specified resource in storage.
Update the specified resource in storage .