for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php namespace Cviebrock\EloquentSluggable\Middleware;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\RouteUrlGenerator;
use Illuminate\Support\Facades\DB;
class RedirectOnOldSlug
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
* @throws \Illuminate\Routing\Exceptions\UrlGenerationException
*/
public function handle(Request $request, \Closure $next)
$route = $request->route();
if ($oldSlug = $this->findOldSlug($route->parameter('slug'))) {
$currentSlug = $this->findSlugFrom($oldSlug);
$path = $this->routeGenerator($request)->to(
$request->route(),
$request->route()
object|string
object<Illuminate\Routing\Route>
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
array_merge($route->parameters(), ['slug' => $currentSlug])
);
return new RedirectResponse($path);
}
return $next($request);
private function findOldSlug($slug)
return DB::table('old_slugs')->where('slug', $slug)->first();
private function findSlugFrom($oldSlug)
return app($oldSlug->model)->find($oldSlug->entity_id)->slug;
private function routeGenerator($request)
return new RouteUrlGenerator(app('url'), $request);
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: