In my Laravel 5.4 project I've got a Helpers.php file. That's working great.
Now I've made a helper that looks like this:
if (! function_exists('issetWithReturn')) {
/**
* @return mixed
*/
function issetWithReturn($values)
{
return isset($collection) ? $collection : '';
}
}
In my OrganisationController.php I use it like this:
/**
* 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),
]);
}
But my editor already gives a sign that $products within issetWithReturn is undefined? Why is that?
When I try this it's all working:
'products' => isset($products) ? $products : '',
composer.json. I rancomposer dumpautoload -o. But that's not the problem.