public function handle($request, \Closure $next) { if (substr($request->getRequestUri(), -1) == '/') { $baseUrl = $request->getBaseUrl(); // try to remove slash at the end of current url $newUrl = substr($request->getRequestUri(), 0, -1); if ($newUrl != $baseUrl) { return redirect(Str::replaceLast($baseUrl, '', $newUrl)); } } return $next($request); }
public function getAttribute($key) { if ($this->isUseImageMax()) { $attribute = parent::getAttribute($key); if (!$attribute) { $profiles = config('imagemax.profiles', []); foreach ($profiles as $profile => $options) { if (Str::endsWith($key, $last = '_' . str_slug($profile, '_'))) { $image = Str::replaceLast($last, '', $key); if (in_array($image, $this->getImagableAttributes()) && $this->getAttribute($image)) { return ImageMax::make($this->getAttribute($image), $options); } } } } return $attribute; } return $this->thumbnailerGetAttribute($key); }
/** * Replace the last occurrence of a given value in the string. * * @param string $search * @param string $replace * @param string $subject * @return string */ function str_replace_last($search, $replace, $subject) { return Str::replaceLast($search, $replace, $subject); }
*/ Str::macro('lastSegment', function ($string, $delimiter) { return Str::segment($string, $delimiter, -1); }); } if (!Str::hasMacro('pop')) { /** * Pop off the last segment of a string based on a delimiter. * Returns the remaining string. * * @param string $string * @param string $delimiter * @return string */ Str::macro('pop', function ($string, $delimiter) { return Str::replaceLast($delimiter . Str::lastSegment($string, $delimiter), '', $string); }); } if (!Str::hasMacro('tease')) { /** * Shortens a string in a pretty way. Removes all double spaces and HTML. * The string is concatenated with the moreTextIndicator. * * @param string $string * @param int $length * @param string $moreTextIndicator * @return string */ Str::macro('tease', function ($string, $length = 200, $moreTextIndicator = '...') { $string = preg_replace("/\\s+/", ' ', strip_tags(trim($string))); if (strlen($string) <= $length) {
/** * Determine the URI from the given method name. * * @param ReflectionMethod $routable * @param string $path * * @return string */ public function getUri(ReflectionMethod $routable, $path) { $uri = $path . '/' . implode('-', array_slice(explode('_', Str::snake($routable->name)), 1)) . '/' . $this->getWildcards($routable); $uri = str_replace('//', '/', $uri); $uri = rtrim($uri, '/'); if (Str::endsWith($uri, 'index')) { $uri = Str::replaceLast('index', '', $uri); } return $uri; }