![](/img/trans.png)
[英]Call to undefined method Illuminate\Routing\RouteFileRegistrar::get() - Error after upgrading from Laravel 5.7 to 5.8
[英]Undefined variable error after upgrading from 5.3 to 5.8 in laravel
我最近刚刚将我的项目从 5.3 升级到 5.8。 但在那之后,我遇到了以下错误:-
这是我的控制器中的代码:-
public function index()
{
$categories = $this->category->getAll();
$plucked_categories = $this->category->pluckedCollection($categories);
$hierarchy = $this->category->getCategoriesHierarchy();
//get through permissions
if (\Gate::denies('view-categories')) {
return redirect('/')->withErrors(config('const.permissions_errors.section'));
} else {
return view('categories.index')->withCategories($categories)
->withCategoriesHierarchy($hierarchy)
->with(compact('plucked_categories'));
}
}
当我像下面这样更改代码时,错误得到解决,但我问为什么withCategoriesHierarchy不起作用。 如果我必须改变这一点,那么我必须改变整个项目。 所以会很麻烦。 所以我正在寻找一些解决方案。 任何帮助将不胜感激。 提前致谢。
return view('categories.index')
->withCategories($categories)
->with(compact('categories_hierarchy','plucked_categories'));
============================
return view('categories.index')
->withCategories($categories)
->with('categories_hierarchy',$hierarchy)
->with(compact('plucked_categories'));
从 Laravel 5.8 版本开始更改 Illuminate\\View 上 __call 魔术函数的实现
旧功能:
public function __call($method, $parameters)
{
if (starts_with($method, 'with')) {
return $this->with(snake_case(substr($method, 4)), $parameters[0]);
}
throw new \BadMethodCallException("Method [$method] does not exist on view.");
}
新功能
public function __call($method, $parameters)
{
if (static::hasMacro($method)) {
return $this->macroCall($method, $parameters);
}
if (! Str::startsWith($method, 'with')) {
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.', static::class, $method
));
}
return $this->with(Str::camel(substr($method, 4)), $parameters[0]);
}
看起来 static::hasMacro($method) 由于某种原因返回 true(需要调试)然后被调用到 macroCall 而不是 $this->with(Str::camel(substr($method, 4)), $parameters [0]);
如果你想检查它,只需将新功能更改为旧功能(当然只是为了测试)如果它有效,请更深入地调试以了解那里发生了什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.