app/Http/Controllers/Admin/AssignmentsController.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-students')) return redirect()->route('admin.assignments.index');
        $validator = Validator::make($request->all(), [
            'tutor_val'             => ['required', 'integer'],
            'student_val'           => ['required', 'integer'],
            'subjects'              => ['nullable', 'Array'],
            'base_invoice'          => ['required', 'string'],
            'base_wage'             => ['required', 'string'],
            'active'                => ['nullable', 'integer'],
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            return redirect(route('admin.assignments.create'));
        }
        $data = $request->all();
        $assignment = Assignment::create([
            'tutor_id'              => $data['tutor_val'],
            'student_id'            => $data['student_val'],
            'base_wage'             => $data['base_wage'],
            'base_invoice'          => $data['base_invoice'],
            'active'                => $data['active'],
        ]);
        if ($assignment == NULL)
        {
            session()->flash('error', "There was an error creating the assignment");
            return redirect(route('admin.users.assignments.create'));
        }
        if (isset($data['subjects']))
        {
            foreach ($data['subjects'] as $subject)
            {
                $assignment->subjects()->attach($subject);
            }
            $assignment->save();
        }
        session() -> flash('success', "The assignment has been created successfully");
        return redirect() -> route('admin.assignments.index');
    }
public function store ( Request $ request ) { if ( Gate :: denies ( 'manage-students' ) ) return redirect ( ) -> route ( 'admin.assignments.index' ) ; $ validator = Validator :: make ( $ request -> all ( ) , [ 'tutor_val' => [ 'required' , 'integer' ] , 'student_val' => [ 'required' , 'integer' ] , 'subjects' => [ 'nullable' , 'Array' ] , 'base_invoice' => [ 'required' , 'string' ] , 'base_wage' => [ 'required' , 'string' ] , 'active' => [ 'nullable' , 'integer' ] , ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( route ( 'admin.assignments.create' ) ) ; } $ data = $ request -> all ( ) ; $ assignment = Assignment :: create ( [ 'tutor_id' => $ data [ 'tutor_val' ] , 'student_id' => $ data [ 'student_val' ] , 'base_wage' => $ data [ 'base_wage' ] , 'base_invoice' => $ data [ 'base_invoice' ] , 'active' => $ data [ 'active' ] , ] ) ; if ( $ assignment == NULL ) { session ( ) -> flash ( 'error' , " There was an error creating the assignment " ) ; return redirect ( route ( 'admin.users.assignments.create' ) ) ; } if ( isset ( $ data [ 'subjects' ] ) ) { foreach ( $ data [ 'subjects' ] as $ subject ) { $ assignment -> subjects ( ) -> attach ( $ subject ) ; } $ assignment -> save ( ) ; } session ( ) -> flash ( 'success' , " The assignment has been created successfully " ) ; return redirect ( ) -> route ( 'admin.assignments.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .