我最近刚刚将项目从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'));
从版本5.8 Laravel开始,在Illuminate \ View上更改了__call magic函数的实现
旧功能:
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]);
如果要检查它,只需将新功能更改为旧功能(当然只是为了测试),如果可以,请对其进行更深入的调试,以了解其中发生的情况。