app/Http/Controllers/Admin/GradesController.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.grades.create');
        }
        $validator = Validator::make($request->all(), [
            'name'      => ['required', 'string', 'min:3', 'max:128'],
            'price_usa' => ['nullable', 'string'],
            'price_alb' => ['nullable', 'string'],
            'price_can' => ['nullable', 'string'],
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            return redirect()->route('admin.grades.create');
        }
        $data = $request->all();
        $grade = Grade::create([
            'name'      => $data['name'],
            'price_usa' => $data['price_usa'],
            'price_alb' => $data['price_alb'],
            'price_can' => $data['price_can']
        ]);
        if($grade == NULL) {
            $request->session()->flash('error', 'There is an error creating Grades!');
            return redirect()->route('admin.grades.create');
        }
        if (isset($data['subjects']))
        {
            foreach ($data['subjects'] as $subject)
            {
                $grade->subjects()->attach($subject);
            }
        }
        $request->session()->flash('success', 'You have modified Grades!');
        return redirect()->route('admin.grades.index');
    }
public function store ( Request $ request ) { if ( Gate :: denies ( 'manage-system' ) ) { return redirect ( ) -> route ( 'admin.grades.create' ) ; } $ validator = Validator :: make ( $ request -> all ( ) , [ 'name' => [ 'required' , 'string' , 'min:3' , 'max:128' ] , 'price_usa' => [ 'nullable' , 'string' ] , 'price_alb' => [ 'nullable' , 'string' ] , 'price_can' => [ 'nullable' , 'string' ] , ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.grades.create' ) ; } $ data = $ request -> all ( ) ; $ grade = Grade :: create ( [ 'name' => $ data [ 'name' ] , 'price_usa' => $ data [ 'price_usa' ] , 'price_alb' => $ data [ 'price_alb' ] , 'price_can' => $ data [ 'price_can' ] ] ) ; if ( $ grade == NULL ) { $ request -> session ( ) -> flash ( 'error' , 'There is an error creating Grades!' ) ; return redirect ( ) -> route ( 'admin.grades.create' ) ; } if ( isset ( $ data [ 'subjects' ] ) ) { foreach ( $ data [ 'subjects' ] as $ subject ) { $ grade -> subjects ( ) -> attach ( $ subject ) ; } } $ request -> session ( ) -> flash ( 'success' , 'You have modified Grades!' ) ; return redirect ( ) -> route ( 'admin.grades.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .