1 year ago

Global variable in controller

Posted 1 year ago by konrms

Hello guys.

I want to create a varible which should be available in two different controller functions. How can I do that?

For example, the first function gets data from a blade and I want to pass it to another function in the same controller. My code sample is this:

  1. The blade which sends obj_id:
<!DOCTYPE html>

<meta charset="UTF-8">



    <form method='post' action="/hard">
        <legend><i> fill number </i></legend>
            OBJECT ID:
            <input name='obj_id' type='text' minlength="8" required="" oninvalid="this.setCustomValidity('At least 8 characters must be used)">

        <input type='submit' value="Υποβολή!">
  1. This is my controller function Roger which gets obj_id from blade.
public function Roger(Request $p)
        $t = $p-> get('obj_id');   //I want $ to be available to other controller functions
  1. How to pass $t to another function (e.g. Roger1) in the same blade and just dd it?
public function Roger1()

I have tried to declade global t but didn't work.

Thanks a lot!

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