platform/admin/app/Http/Requests/StoreSession.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 = [
            'title' => ['required', 'string'],
            'session_type_id' => ['required', 'exists:session_types,id'],
            'speaker_id' => ['required', 'exists:speakers,id'],
            'room_id' => ['required', 'exists:rooms,id'],
            'start_time' => ['required', 'string', 'date_format:d/m/Y H:i', 'after_or_equal:'. $event->date],
            'end_time' => ['required', 'string', 'date_format:d/m/Y H:i', 'after:start_time'],
            'description' => ['nullable', 'string']
        ];
        if (!empty($this->request->get('room_id')) &&
            !empty($this->request->get('start_time')) &&
            !empty($this->request->get('end_time'))) {
            $postStartTime = Carbon::parse(str_replace('/', '-', $this->request->get('start_time')))->addMinutes(1);
            $postEndTime = Carbon::parse(str_replace('/', '-', $this->request->get('end_time')))->subMinutes(1);
            $isExits = $this->checkConflictWithOtherSession($postStartTime, $postEndTime);
            if ($isExits) {
                $rule['start_time'][] = function ($attribute, $value, $fail) {
                    $fail('This time is already has session registered');
                };
                $rule['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 = [ 'title' => [ 'required' , 'string' ] , 'session_type_id' => [ 'required' , 'exists:session_types,id' ] , 'speaker_id' => [ 'required' , 'exists:speakers,id' ] , 'room_id' => [ 'required' , 'exists:rooms,id' ] , 'start_time' => [ 'required' , 'string' , 'date_format:d/m/Y H:i' , 'after_or_equal:' . $ event -> date ] , 'end_time' => [ 'required' , 'string' , 'date_format:d/m/Y H:i' , 'after:start_time' ] , 'description' => [ 'nullable' , 'string' ] ] ; if ( ! empty ( $ this -> request -> get ( 'room_id' ) ) && ! empty ( $ this -> request -> get ( 'start_time' ) ) && ! empty ( $ this -> request -> get ( 'end_time' ) ) ) { $ postStartTime = Carbon :: parse ( str_replace ( '/' , '-' , $ this -> request -> get ( 'start_time' ) ) ) -> addMinutes ( 1 ) ; $ postEndTime = Carbon :: parse ( str_replace ( '/' , '-' , $ this -> request -> get ( 'end_time' ) ) ) -> subMinutes ( 1 ) ; $ isExits = $ this -> checkConflictWithOtherSession ( $ postStartTime , $ postEndTime ) ; if ( $ isExits ) { $ rule [ 'start_time' ] [ ] = function ( $ attribute , $ value , $ fail ) { $ fail ( 'This time is already has session registered' ) ; } ; $ rule [ '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 .