src/Models/Appointment.php
public function scopeAffectingInterval($query, Carbon $startAt, Carbon $finishAt)
    {
        $startAt->timezone('UTC');
        $finishAt->timezone('UTC');

        return $query
            ->where(function ($query) use ($startAt, $finishAt) {

                $query->where(function ($query) use ($startAt, $finishAt) {
                    $query->where('finish_at', '>=', $finishAt)
                            ->where('start_at', '<', $startAt);
                })
                ->orWhere(function ($query) use ($startAt, $finishAt) {
                    $query->where('finish_at', '<=', $finishAt)
                            ->where('finish_at', '>', $startAt);
                })
                ->orWhere(function ($query) use ($startAt, $finishAt) {
                    $query->where('start_at', '>=', $startAt)
                            ->where('start_at', '<', $finishAt);
                });
//                ->orWhere(function ($query) use ($startAt, $finishAt) {
//                    $query->where('start_at', '>', $startAt)
//                            ->where('finish_at', '>', $finishAt);
//                });

            });
    }
public function scopeAffectingInterval($query, Carbon $startAt, Carbon $finishAt)
    {
        $startAt->timezone('UTC');
        $finishAt->timezone('UTC');

        return $query
            ->where(function ($query) use ($startAt, $finishAt) {

                $query->where(function ($query) use ($startAt, $finishAt) {
                    $query->where('finish_at', '>=', $finishAt)
                            ->where('start_at', '<', $startAt);
                })
                ->orWhere(function ($query) use ($startAt, $finishAt) {
                    $query->where('finish_at', '<=', $finishAt)
                            ->where('finish_at', '>', $startAt);
                })
                ->orWhere(function ($query) use ($startAt, $finishAt) {
                    $query->where('start_at', '>=', $startAt)
                            ->where('start_at', '<', $finishAt);
                });
//                ->orWhere(function ($query) use ($startAt, $finishAt) {
//                    $query->where('start_at', '>', $startAt)
//                            ->where('finish_at', '>', $finishAt);
//                });

            });
    }
public function scopeAffectingInterval ( $ query , Carbon $ startAt , Carbon $ finishAt ) { $ startAt -> timezone ( 'UTC' ) ; $ finishAt -> timezone ( 'UTC' ) ; return $ query -> where ( function ( $ query ) use ( $ startAt , $ finishAt ) { $ query -> where ( function ( $ query ) use ( $ startAt , $ finishAt ) { $ query -> where ( 'finish_at' , '>=' , $ finishAt ) -> where ( 'start_at' , '<' , $ startAt ) ; } ) -> orWhere ( function ( $ query ) use ( $ startAt , $ finishAt ) { $ query -> where ( 'finish_at' , '<=' , $ finishAt ) -> where ( 'finish_at' , '>' , $ startAt ) ; } ) -> orWhere ( function ( $ query ) use ( $ startAt , $ finishAt ) { $ query -> where ( 'start_at' , '>=' , $ startAt ) -> where ( 'start_at' , '<' , $ finishAt ) ; } ) ; //                ->orWhere(function ($query) use ($startAt, $finishAt) { //                    $query->where('start_at', '>', $startAt) //                            ->where('finish_at', '>', $finishAt); //                }); } ) ; }
Soft check of time interval affectation

@param Illuminate\Database\Query $query
@param Carbon                    $startAt
@param Carbon                    $finishAt

@return Illuminate\Database\Query
Soft check of time interval affectation