platform/admin/app/Http/Requests/UpdateSession.php
/**
     * Get the validation rules that apply to the request.
     * @param $eventRepository
     * @return array
     */
Get the validation rules that apply to the request.
@param $eventRepository
@return array
Get the validation rules that apply to the request . @param $eventRepository @return array
public function rules(EventRepository $eventRepository)
    {
        $event = $eventRepository->findById($this->event);
        $rule = [
            'session_title' => ['required', 'string'],
            'session_session_type_id' => ['required', 'exists:session_types,id'],
            'session_speaker_id' => ['required', 'exists:speakers,id'],
            'session_room_id' => ['required', 'exists:rooms,id'],
            'session_start_time' => ['required', 'string', 'date_format:d/m/Y H:i', 'after_or_equal:'. $event->date],
            'session_end_time' => ['required', 'string', 'date_format:d/m/Y H:i', 'after:start_time'],
            'session_description' => ['nullable', 'string']
        ];
        if (!empty($this->request->get('session_room_id')) &&
            !empty($this->request->get('session_start_time')) &&
            !empty($this->request->get('session_end_time'))) {
            $sessionModel = Session::find($this->session_id);
            $postStartTime = str_replace('/', '-', $this->request->get('session_start_time'));
            $postEndTime = str_replace('/', '-', $this->request->get('session_end_time'));
            if (!$this->compareTime(
                $sessionModel->start_time,
                $sessionModel->end_time,
                $postStartTime,
                $postEndTime
            )) {
                $postStartTime = Carbon::parse($postStartTime)->addMinutes(1);
                $postEndTime = Carbon::parse($postEndTime)->subMinutes(1);
                if (!is_null($this->checkInPostTimeRange($postStartTime, $postEndTime))) {
                    $isExists = true;
                } else {
                    $isExists = $this->checkConflictWithOtherSession($sessionModel, $postStartTime, $postEndTime);
                }
                if ($isExists) {
                    $rule['session_start_time'][] = function ($attribute, $value, $fail) {
                        $fail('This time is already has session registered');
                    };
                    $rule['session_end_time'][] = function ($attribute, $value, $fail) {
                        $fail('This time is already has session registered');
                    };
                }
            }
        }
        return $rule;
    }
public function rules ( EventRepository $ eventRepository ) { $ event = $ eventRepository -> findById ( $ this -> event ) ; $ rule = [ 'session_title' => [ 'required' , 'string' ] , 'session_session_type_id' => [ 'required' , 'exists:session_types,id' ] , 'session_speaker_id' => [ 'required' , 'exists:speakers,id' ] , 'session_room_id' => [ 'required' , 'exists:rooms,id' ] , 'session_start_time' => [ 'required' , 'string' , 'date_format:d/m/Y H:i' , 'after_or_equal:' . $ event -> date ] , 'session_end_time' => [ 'required' , 'string' , 'date_format:d/m/Y H:i' , 'after:start_time' ] , 'session_description' => [ 'nullable' , 'string' ] ] ; if ( ! empty ( $ this -> request -> get ( 'session_room_id' ) ) && ! empty ( $ this -> request -> get ( 'session_start_time' ) ) && ! empty ( $ this -> request -> get ( 'session_end_time' ) ) ) { $ sessionModel = Session :: find ( $ this -> session_id ) ; $ postStartTime = str_replace ( '/' , '-' , $ this -> request -> get ( 'session_start_time' ) ) ; $ postEndTime = str_replace ( '/' , '-' , $ this -> request -> get ( 'session_end_time' ) ) ; if ( ! $ this -> compareTime ( $ sessionModel -> start_time , $ sessionModel -> end_time , $ postStartTime , $ postEndTime ) ) { $ postStartTime = Carbon :: parse ( $ postStartTime ) -> addMinutes ( 1 ) ; $ postEndTime = Carbon :: parse ( $ postEndTime ) -> subMinutes ( 1 ) ; if ( ! is_null ( $ this -> checkInPostTimeRange ( $ postStartTime , $ postEndTime ) ) ) { $ isExists = true ; } else { $ isExists = $ this -> checkConflictWithOtherSession ( $ sessionModel , $ postStartTime , $ postEndTime ) ; } if ( $ isExists ) { $ rule [ 'session_start_time' ] [ ] = function ( $ attribute , $ value , $ fail ) { $ fail ( 'This time is already has session registered' ) ; } ; $ rule [ 'session_end_time' ] [ ] = function ( $ attribute , $ value , $ fail ) { $ fail ( 'This time is already has session registered' ) ; } ; } } } return $ rule ; }
Get the validation rules that apply to the request.
Get the validation rules that apply to the request .
/* if have change time range*/