app/Http/Controllers/Admin/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(), [
            'assignment_id'     => ['required', 'integer'],
            'session_date'      => ['required', 'date'],
            'session_duration'  => ['required', 'string'],
            'notes'             => ['nullable', 'string']
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            return redirect()->route('admin.sessions.create');
        }
        $data = $request->all();
        $durations = $this->getAllDurations();
        $session_duration = array_search($data['session_duration'], $durations);
        $session = Session::create([
            'assignment_id'         => $data['assignment_id'],
            'session_date'          => $data['session_date'],
            'session_duration'      => number_format($session_duration, 2),
            'session_notes'         => $data['notes']
        ]);
        if ($session == NULL)
        {
            $request->session()->flash('error', "There was an error logging hours");
            return redirect()->route('admin.sessions.create');
        }
        $request->session()->flash('success', "The hours has been logged successfully");
        return redirect()->route('admin.sessions.index');
    }
public function store ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'assignment_id' => [ 'required' , 'integer' ] , 'session_date' => [ 'required' , 'date' ] , 'session_duration' => [ 'required' , 'string' ] , 'notes' => [ 'nullable' , 'string' ] ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.sessions.create' ) ; } $ data = $ request -> all ( ) ; $ durations = $ this -> getAllDurations ( ) ; $ session_duration = array_search ( $ data [ 'session_duration' ] , $ durations ) ; $ session = Session :: create ( [ 'assignment_id' => $ data [ 'assignment_id' ] , 'session_date' => $ data [ 'session_date' ] , 'session_duration' => number_format ( $ session_duration , 2 ) , 'session_notes' => $ data [ 'notes' ] ] ) ; if ( $ session == NULL ) { $ request -> session ( ) -> flash ( 'error' , " There was an error logging hours " ) ; return redirect ( ) -> route ( 'admin.sessions.create' ) ; } $ request -> session ( ) -> flash ( 'success' , " The hours has been logged successfully " ) ; return redirect ( ) -> route ( 'admin.sessions.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .