app/Http/Controllers/SubjectController.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)
    {
         $create_new_validator = $this->validator($request->all());
        if ($create_new_validator->fails()) {
            $this->throwValidationException(
                $request, $create_new_validator
            );
        } else {
            $priorities = Priority::all();
            $subject = Subject::find($id);
            $subject->subject = $request->input('subject');
            $priorityArray = [];
            foreach ($priorities as $a_priority) {
                if ($request->input($a_priority->name) != null) {
                    array_push($priorityArray, $request->input($a_priority->name));
                }
            }
            $subject->save();
            $subject->priorities()->detach();
            $subject->priorities()->attach($priorityArray);
            return redirect('subject')->with('status', 'Asunto actualizado éxitosamente');
        }
    }
public function update ( Request $ request , $ id ) { $ create_new_validator = $ this -> validator ( $ request -> all ( ) ) ; if ( $ create_new_validator -> fails ( ) ) { $ this -> throwValidationException ( $ request , $ create_new_validator ) ; } else { $ priorities = Priority :: all ( ) ; $ subject = Subject :: find ( $ id ) ; $ subject -> subject = $ request -> input ( 'subject' ) ; $ priorityArray = [ ] ; foreach ( $ priorities as $ a_priority ) { if ( $ request -> input ( $ a_priority -> name ) != null ) { array_push ( $ priorityArray , $ request -> input ( $ a_priority -> name ) ) ; } } $ subject -> save ( ) ; $ subject -> priorities ( ) -> detach ( ) ; $ subject -> priorities ( ) -> attach ( $ priorityArray ) ; return redirect ( 'subject' ) -> with ( 'status' , 'Asunto actualizado éxitosamente') ; } }
Update the specified resource in storage.
Update the specified resource in storage .
// THE SUCCESSFUL RETURN