Answer the question
In order to leave comments, you need to log in
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
[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
<?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());
}
}
Answer the question
In order to leave comments, you need to log in
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);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question