app/Http/Controllers/Tutor/ReportCardsController.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)
    {
        $validator = Validator::make($request->all(), [
            'sname'                 => ['required', 'integer'],
            'student_prepared'      => ['required', 'integer'],
            'questions_ready'       => ['required', 'integer'],
            'pay_attention'         => ['required', 'integer'],
            'weaknesses'            => ['required', 'string'],
            'listen_to_suggestions' => ['required', 'integer'],
            'improvements'          => ['required', 'string'],
            'other_comments'        => ['required', 'string'],
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            return redirect()->route('tutor.reportcards.create');
        }
        $data = $request->all();
        $student = User::where('id', $data['sname'])->first();
        $tutor_id = Auth::User()->id;
        $assignments = Assignment::where(function($assignment) use ($student, $tutor_id) {
            return $assignment -> where('tutor_id', $tutor_id)
            -> where('student_id', $student->id);
        })->get();
        $subjects_array = Array();
        foreach ($assignments as $assignment) 
        {
            $subjects = $assignment->subjects()->get();
            foreach ($subjects as $subject) {
                $subjects_array[] = $subject->name;
            }
        }
        $subjects = "";
        foreach ($subjects_array as $subject)
        {
            $subjects .= $subject . ',';
        }
        $subjects = rtrim($subjects ,',');
        $reportcard = ProgressReport::create([
            'tutor_id'                  => $tutor_id,
            'student_id'                => $data['sname'],
            'grade_id'                  => $student->grade_id,
            'subjects'                  => $subjects,
            'student_prepared'          => $data['student_prepared'],
            'questions_ready'           => $data['questions_ready'],
            'pay_attention'             => $data['pay_attention'],
            'weaknesses'                => $data['weaknesses'],
            'listen_to_suggestions'     => $data['listen_to_suggestions'],
            'improvements'              => $data['improvements'],
            'other_comments'            => $data['other_comments']
        ]);
        if ($reportcard == NULL)
        {
            $request->session()->flash('error', "There is an error seding Report card.");
            return redirect()->route('tutor.reportcards.create');
        }
        $request->session()->flash('success', "Report card sent successfully.");
        return redirect()->route('tutor.reportcards.index');
    }
public function store ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'sname' => [ 'required' , 'integer' ] , 'student_prepared' => [ 'required' , 'integer' ] , 'questions_ready' => [ 'required' , 'integer' ] , 'pay_attention' => [ 'required' , 'integer' ] , 'weaknesses' => [ 'required' , 'string' ] , 'listen_to_suggestions' => [ 'required' , 'integer' ] , 'improvements' => [ 'required' , 'string' ] , 'other_comments' => [ 'required' , 'string' ] , ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'tutor.reportcards.create' ) ; } $ data = $ request -> all ( ) ; $ student = User :: where ( 'id' , $ data [ 'sname' ] ) -> first ( ) ; $ tutor_id = Auth :: User ( ) -> id ; $ assignments = Assignment :: where ( function ( $ assignment ) use ( $ student , $ tutor_id ) { return $ assignment -> where ( 'tutor_id' , $ tutor_id ) -> where ( 'student_id' , $ student -> id ) ; } ) -> get ( ) ; $ subjects_array = Array ( ) ; foreach ( $ assignments as $ assignment ) { $ subjects = $ assignment -> subjects ( ) -> get ( ) ; foreach ( $ subjects as $ subject ) { $ subjects_array [ ] = $ subject -> name ; } } $ subjects = " " ; foreach ( $ subjects_array as $ subject ) { $ subjects .= $ subject . ',' ; } $ subjects = rtrim ( $ subjects , ',' ) ; $ reportcard = ProgressReport :: create ( [ 'tutor_id' => $ tutor_id , 'student_id' => $ data [ 'sname' ] , 'grade_id' => $ student -> grade_id , 'subjects' => $ subjects , 'student_prepared' => $ data [ 'student_prepared' ] , 'questions_ready' => $ data [ 'questions_ready' ] , 'pay_attention' => $ data [ 'pay_attention' ] , 'weaknesses' => $ data [ 'weaknesses' ] , 'listen_to_suggestions' => $ data [ 'listen_to_suggestions' ] , 'improvements' => $ data [ 'improvements' ] , 'other_comments' => $ data [ 'other_comments' ] ] ) ; if ( $ reportcard == NULL ) { $ request -> session ( ) -> flash ( 'error' , " There is an error seding Report card. " ) ; return redirect ( ) -> route ( 'tutor.reportcards.create' ) ; } $ request -> session ( ) -> flash ( 'success' , " Report card sent successfully. " ) ; return redirect ( ) -> route ( 'tutor.reportcards.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .