public function segments(int $index = null) { $segments = collect(explode('/', $this->path()))->filter(function ($value) { return $value !== ''; })->values()->toArray(); if (!is_null($index)) { return $this->segment($index); } return $segments; }