zettz
74
15
Laravel

Share value between function in same controller

Posted 2 months ago by zettz

Hi there, I need help on how to share result between function on the same controller.

For example: search function results can be reuse at another function in the same controller.

Current controller:

public function searchProduct ()
{
    $search = Product::find(\Request::get('barcode'));
}
public function show ()
{
    $user = User::All();
    $result = $this->searchProduct(); // this line always return null
    return view('products.result', compact('user', 'result'));
}

So, how can I get the searchProduct() result on the show() function?

Thank you.

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.