app/Http/Controllers/Tutor/SessionsController.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(), [
            'student'           => ['required', 'integer'],
            'session_date'      => ['required', 'date'],
            'session_duration'  => ['required', 'string'],
            'session_notes'     => ['required', 'string'],
            'method'            => ['required', 'string']
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            return redirect()->route('tutor.sessions.create');
        }
        $tutor_id = Auth::user()->id;
        $assignment_id = Assignment::where(function($assignment) use ($tutor_id, $request){
            return $assignment->where('tutor_id', $tutor_id)
            -> where('student_id', $request['student']);
        })->first()['id'];
        $data = $request->all();
        $session = Session::create([
            'assignment_id'     => $assignment_id,
            'session_date'      => $data['session_date'],
            'session_duration'  => $data['session_duration'],
            'session_notes'     => $data['session_notes'],
            'method'            => $data['method']
        ]);
        if ($session == NULL)
        {
            $request->session()->flash('error', "There is an error logging your session!");
            return redirect()->route('tutor.sessions.create');
        }
        $request->session()->flash('success', "Your session logged successfully");
        return redirect()->route('tutor.sessions.index');
    }
public function store ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'student' => [ 'required' , 'integer' ] , 'session_date' => [ 'required' , 'date' ] , 'session_duration' => [ 'required' , 'string' ] , 'session_notes' => [ 'required' , 'string' ] , 'method' => [ 'required' , 'string' ] ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'tutor.sessions.create' ) ; } $ tutor_id = Auth :: user ( ) -> id ; $ assignment_id = Assignment :: where ( function ( $ assignment ) use ( $ tutor_id , $ request ) { return $ assignment -> where ( 'tutor_id' , $ tutor_id ) -> where ( 'student_id' , $ request [ 'student' ] ) ; } ) -> first ( ) [ 'id' ] ; $ data = $ request -> all ( ) ; $ session = Session :: create ( [ 'assignment_id' => $ assignment_id , 'session_date' => $ data [ 'session_date' ] , 'session_duration' => $ data [ 'session_duration' ] , 'session_notes' => $ data [ 'session_notes' ] , 'method' => $ data [ 'method' ] ] ) ; if ( $ session == NULL ) { $ request -> session ( ) -> flash ( 'error' , " There is an error logging your session! " ) ; return redirect ( ) -> route ( 'tutor.sessions.create' ) ; } $ request -> session ( ) -> flash ( 'success' , " Your session logged successfully " ) ; return redirect ( ) -> route ( 'tutor.sessions.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .