Currently I can get a route in a controller by injecting it into the method I want to use it in.
<?php namespace App\Http\Controllers;
use Illuminate\Routing\Route;
class HomeController extends Controller
{
public function getIndex(Route $route)
{
echo $route->getActionName();
}
}
However I'm trying to perform something similar in middleware but can't get it going.
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Routing\Route;
use Illuminate\Contracts\Routing\Middleware;
class SetView implements Middleware {
protected $route;
public function __construct(Route $route)
{
$this->route = $route;
}
public function handle($request, Closure $next)
{
echo $this->route->getActionName();
return $next($request);
}
}
Getting an error.
Unresolvable dependency resolving [Parameter #0 [ <required> $methods ]] in class Illuminate\Routing\Route
Not really sure what to do with that. Don't really care if it's a route or not, but need to get that action name somehow.