[英]Undefined variable error after upgrading from 5.3 to 5.8 in laravel
I just recently upgraded my project from 5.3 to 5.8.我最近刚刚将我的项目从 5.3 升级到 5.8。 but after that, I'm having the following error:-
但在那之后,我遇到了以下错误:-
This is the code in my controller:-这是我的控制器中的代码:-
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'));
}
}
When I change the code like this below the error gets solved but I'm asking why withCategoriesHierarchy does not work.当我像下面这样更改代码时,错误得到解决,但我问为什么withCategoriesHierarchy不起作用。 If I have to change this then I have to change in the entire project.
如果我必须改变这一点,那么我必须改变整个项目。 so that will be troublesome.
所以会很麻烦。 So I'm looking for some solution.
所以我正在寻找一些解决方案。 any help will be appreciated.
任何帮助将不胜感激。 thanks in advance.
提前致谢。
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'));
Since version 5.8 Laravel change the implementation of __call magic function on Illuminate\\View从 Laravel 5.8 版本开始更改 Illuminate\\View 上 __call 魔术函数的实现
Old function:旧功能:
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.");
}
New function新功能
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]);
}
Looks like static::hasMacro($method) return true for some reason ( need to debug ) then is called to macroCall and not to $this->with(Str::camel(substr($method, 4)), $parameters[0]);看起来 static::hasMacro($method) 由于某种原因返回 true(需要调试)然后被调用到 macroCall 而不是 $this->with(Str::camel(substr($method, 4)), $parameters [0]);
if you want to check it, just change the new function to old one ( just for testing of course ) if it's work, debug it deeper to understand what is happening there.如果你想检查它,只需将新功能更改为旧功能(当然只是为了测试)如果它有效,请更深入地调试以了解那里发生了什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.