app/Http/Controllers/Admin/GradesController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Grade  $grade
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Grade $grade)
    {
        if (Gate::denies('manage-system')) {
            return redirect()->route('admin.grades.edit', $grade);
        }
        $validator = Validator::make($request->all(), [
            'name'      => ['required', 'string', 'min:3', "max:128"],
            'price_usa' => ['nullable', 'string'],
            'price_can' => ['nullable', 'string'],
            'price_alb' => ['nullable', 'string'],
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            return redirect()->route('admin.grades.edit', $grade);
        }
        $data = $request->all();
        if (isset($data['subjects'])) $grade->subjects()->sync($data['subjects']);
        $grade->name = $data['name'];
        if (isset($data['price_usa'])) $grade->price_usa = $data['price_usa'];
        if (isset($data['price_alb'])) $grade->price_alb = $data['price_alb'];
        if (isset($data['price_can'])) $grade->price_can = $data['price_can'];
        if(!$grade->save()) {
            $request->session()->flash('error', 'There is an error modifying Grades!');
            return redirect()->route('admin.grades.edit', $grade);
        }
        if (isset($data['subjects']))
        {
            $grade->subjects()->sync($data['subjects']);
        }
        $request->session()->flash('success', 'You have modified Grades!');
        return redirect()->route('admin.grades.index');
    }
public function update ( Request $ request , Grade $ grade ) { if ( Gate :: denies ( 'manage-system' ) ) { return redirect ( ) -> route ( 'admin.grades.edit' , $ grade ) ; } $ validator = Validator :: make ( $ request -> all ( ) , [ 'name' => [ 'required' , 'string' , 'min:3' , " max:128 " ] , 'price_usa' => [ 'nullable' , 'string' ] , 'price_can' => [ 'nullable' , 'string' ] , 'price_alb' => [ 'nullable' , 'string' ] , ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.grades.edit' , $ grade ) ; } $ data = $ request -> all ( ) ; if ( isset ( $ data [ 'subjects' ] ) ) $ grade -> subjects ( ) -> sync ( $ data [ 'subjects' ] ) ; $ grade -> name = $ data [ 'name' ] ; if ( isset ( $ data [ 'price_usa' ] ) ) $ grade -> price_usa = $ data [ 'price_usa' ] ; if ( isset ( $ data [ 'price_alb' ] ) ) $ grade -> price_alb = $ data [ 'price_alb' ] ; if ( isset ( $ data [ 'price_can' ] ) ) $ grade -> price_can = $ data [ 'price_can' ] ; if ( ! $ grade -> save ( ) ) { $ request -> session ( ) -> flash ( 'error' , 'There is an error modifying Grades!' ) ; return redirect ( ) -> route ( 'admin.grades.edit' , $ grade ) ; } if ( isset ( $ data [ 'subjects' ] ) ) { $ grade -> subjects ( ) -> sync ( $ data [ 'subjects' ] ) ; } $ request -> session ( ) -> flash ( 'success' , 'You have modified Grades!' ) ; return redirect ( ) -> route ( 'admin.grades.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .