【发布时间】:2017-07-18 09:28:44
【问题描述】:
在我的 Laravel 5.4 项目中,我有一个 Helpers.php 文件。这很好用。
现在我制作了一个看起来像这样的助手:
if (! function_exists('issetWithReturn')) {
/**
* @return mixed
*/
function issetWithReturn($values)
{
return isset($collection) ? $collection : '';
}
}
在我的OrganisationController.php 我这样使用它:
/**
* Show all organisations.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
if (Gate::allows('edit-organisations')) {
$products = $this->productRepo->getAll();
}
return view('organisation.index')->with([
'products' => issetWithReturn($products),
]);
}
但是我的编辑器已经给出了issetWithReturn 中的$products 未定义的标志?这是为什么呢?
当我尝试这个时,一切正常:
'products' => isset($products) ? $products : '',
【问题讨论】:
-
你是否包含了帮助文件?
-
是的,我使用了更多的辅助函数并且它们工作正常。它在我的
composer.json中。我跑了composer dumpautoload -o。但这不是问题。