kaaps
499
4
Laravel

Global Variable in Controller

Posted 2 years ago by kaaps

Hi,

I was wondering the best way if possible to create a global variable in my controller, because my problem is I am trying to insert data inside the table 'B' that has a collumn that needs a specific ID from the table 'A';

public function show($id)
    {
        $user = User::find($id);
        return view('user.show', compact('user'));
    }

Can I make this $id a Global Variable, so I can use in other functions insted of passing always on the route?

Thanks

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

Reply to

Use Markdown with GitHub-flavored code blocks.