A
A
Anatoly2017-01-29 22:25:06
Web development
Anatoly, 2017-01-29 22:25:06

Laravel error on artisan route:list?

Guys, good afternoon.
I can't figure out what the problem is.
When I call a command like php artisan route:list , I get an error

[Symfony\Component\Debug\Exception\FatalErrorException]
Call to a member function getPrefix() on a non-object

and writes in the logs
[2017-01-30 01:24:22] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to a member function getPrefix() on a non-object' in **** *******\app\Http\Controllers\AdminController.php:19

Whole controller code
<?php namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Events\AuthTime;
use Auth;
class AdminController extends Controller
{
public $path;
public function __construct(Request $request)
{
event(new AuthTime(Auth::user()));
$this->path = $request->path();
view()->share('currentPrefix', $request->route()->getPrefix());
view()->share('currentRouteName', $this->currentRouteName());
}
}

Laravel version 5.2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor, 2017-01-29
@les-anatoliy

The call to php artisan route:list uses the controller constructors to get the middleware that can be set there.
$request->route() returns null because no route is actually in use at the moment.
You need to wrap it in a check:

$route = $request->route();
$prefix = $route ? $route->getPrefix() : null;
view()->share('currentPrefix', $prefix);

Or via App::runningInConsole().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question