0

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 : '',
2
  • 1
    did you include helper file? Commented Jul 18, 2017 at 9:30
  • Yes I use more helper functions and they are working correctly. It's in my composer.json. I ran composer dumpautoload -o. But that's not the problem. Commented Jul 18, 2017 at 9:31

1 Answer 1

1

Well you are passing a parameter called $values but inside the function using a varible called $collection

So basically its a typo

if (! function_exists('issetWithReturn')) {
    /**
     * @return mixed
     */
    function issetWithReturn($values)
    {
        return isset($value) ? $value : '';
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.