Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

onurzdgn's avatar

1 Controller, 2 function and redirect

I have a controller and I have tree different function. One for ZeroMQ connection:

 //All ZMQ request is coming here and sending
    function sendZmq($data = array())
    {

        $queue = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_REQ);
        $queue->connect("tcp://127.0.0.1:6116");
        $queue->setSockOpt(ZMQ::SOCKOPT_LINGER, 0);

        for ($i = 0; $i < count($data); $i++) {

            if ($i == (count($data) - 1)) {
                $queue->send($data[$i], ZMQ::MODE_NOBLOCK);
            } else {
                $queue->send($data[$i], ZMQ::MODE_SNDMORE);
            }
        }

        $answer = $queue->recvMulti();

        return $answer;
    }

this is working corectly. Other Controllers are one for open page with 'buttonData', ('buttonData' is workinng). Other one is post request, also post request work to. Here my Controllers:

//Open 'Base Station' page
    public function baseStation()
    {
        $buttonData = $this->checkScanButton('buttonData');

		if (!empty(session('res'))) {
            $res = 'res here';
        } else {
            $res = 'empty';
        }

        return view('baseStation', compact('buttonData',  'res'));
    }

//Post datas to 'sendZmq' function and post it.
 public function ears(Request $request)
    {
        $boss = $request->input('boss');
        $bossTwo= $request->input('bossTwo');
        $optType = $request->input('optType');

        $one= $boss;
        $two= $bossTwo;

        if ($optType == 0) {
            $flag = "FREG";
        } elseif ($optType == 1) {
            $flag = 'STOP';
        } elseif ($optType == -1) {
            $flag = 'SALL';
        }

        $sendData = array();
        $sendData[] = $flag;
        $sendData[] = $one;
        $sendData[] = $two;

        $response = $this->sendZmq($sendData);

        $res = $response;

        $buttonData = $this->checkScanButton('buttonData');

        return redirect('baseStation')->with('buttonData', 'res');
    }

Okay I can post datas and I can reach the 'response' (when I use dd I show 'response') but problem start after, I can't send 'response', 'ears' function to 'baseStation' function. I am using 'redirect', becasue ı can't see lacalhost/ears just I want to see loaclhost/baseStation. My question is how can I send my 'response'^to my screen? I am sorry it is to long.

0 likes
1 reply
onurzdgn's avatar
onurzdgn
OP
Best Answer
Level 2

Okay I find it I update like tihs:

//Open 'Base Station' page
    public function baseStation()
    {
        $buttonData = $this->checkScanButton('buttonData');

		if (!empty(session('res'))) {
            $res = 'res here';
        }elseif (empty(session('res'))) {
            $res = 'res empty';
        } else {
            $res = 'error';
        }

        return view('baseStation', compact('buttonData',  'res'));
    }

//Post datas to 'sendZmq' function and post it.
 public function ears(Request $request)
    {
        $boss = $request->input('boss');
        $bossTwo= $request->input('bossTwo');
        $optType = $request->input('optType');

        $one= $boss;
        $two= $bossTwo;

        if ($optType == 0) {
            $flag = "FREG";
        } elseif ($optType == 1) {
            $flag = 'STOP';
        } elseif ($optType == -1) {
            $flag = 'SALL';
        }

        $sendData = array();
        $sendData[] = $flag;
        $sendData[] = $one;
        $sendData[] = $two;

        $response = $this->sendZmq($sendData);

        $res = $response;

        $buttonData = $this->checkScanButton('buttonData');

        return redirect('baseStation')->with('buttonData', $buttonData)->with('res', $res);
    }

Please or to participate in this conversation.