D
D
Dmitry Shelygin2018-11-30 21:26:13
Laravel
Dmitry Shelygin, 2018-11-30 21:26:13

Why is redirect() not returning a page?

Laravel 5.7
In a controller, when an error is received from the API, it must be returned to the page.
redirect() works but doesn't render the page. Just a white screen.

if ($result['error']) {
            if (strpos($result['error_description'], 'Task not found')) {
                // echo "Неверно введен номер задачи";
                return redirect()->route('home');
                // die;
            }
        }

return view('welcome');
does the same
here is the code of the whole function
private function getTask($request)
    {
        $number = intval($request->number);

        $queryUrl = 'https://'.HomeController::DOMAIN.'.bitrix24.ru/rest/71/000000000000/task.item.getdata.json';
        $queryData = http_build_query(array(
            'TASKID' => $number
        ));

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_SSL_VERIFYPEER => 0,
            CURLOPT_POST => 1,
            CURLOPT_HEADER => 0,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => $queryUrl,
            CURLOPT_POSTFIELDS => $queryData,
        ));

        $result = curl_exec($curl);
        curl_close($curl);

        $result = json_decode($result, 1);

        if ($result['error']) {
            if (strpos($result['error_description'], 'Task not found')) {
                echo "Неверно введен номер задачи";
                return view('welcome');
                // die;
            }
        }

        dd($result);
    }

This function is called from another function, which, in turn, is called when Submit is clicked on the form.
If instead of calling this function I do redirect or return view, then everything works fine

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question