E
E
Evgeny Musonov2020-02-09 07:37:40
Laravel
Evgeny Musonov, 2020-02-09 07:37:40

How does the redirect()->send() function work with sessions?

I call a redirect in a class that is called in the controller

redirect()->route('error')->with('message', $exception->getMessage())->send();

On such a route
Route::get('/error', function (Request $request) {
    $value = $request->session()->get('message', function () {
        return 'default';
    });
    echo $value;
})->name('error');

The session value messageis always default. What could be the problem?

UPD:
The method that I call in the controller
$imageUploader->upload()->resize();
The method itself
public function resize($width, $height, $dirForSave, $quality = 100)
    {
        $params = [
            'width'      => $width,
            'height'     => $height,
            'dirForSave' => $dirForSave
        ];

        try {
            $this->validateResizeParams($params);
            if (!is_null($this->file)) {
              //Тут уменьшаю изображение
            } else {
                // Throw Exception
            }
        } catch (Exception $exception) {
            Log::error($exception->getMessage());
            FileHelper::deleteDir($this->filePath);
            redirect()->route('error')->with('message', $exception->getMessage())->send();
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Musonov, 2020-02-09
@evmusonov

Solved the problem with the functionabort(500, 'error message');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question