Laravel Redirect-> c (key, val) not working

I would like to send information from one function to another using a function ->with(key, val), but it does not work. I tried a lot of things, but this does not work.

Here is my actual setup (I am using laravel 5.2):

routes.php

Route::group(['middleware' => ['web']], function() {
    Route::get("/test1", "InfoController@test1");
    Route::get("/test2", "InfoController@test2");
});

InfoController.php

class InfoController extends Controller
{
    public function test1(){
        return View::make("infos");
    }

    public function test2(){
        return Redirect::to("/test1")->with("hello", "world");
    }
}

Infos.blade.php

{{\Illuminate\Support\Facades\Session::get("hello")}}

Sit blank → no output.

Where is the problem?

+4
source share
2 answers

with()passes session data, not a variable. Therefore, you need to use the method get()to get the data:

{{ Session::get('hello') }}

Also, if you are using 5.2.27 or higher, uninstall the webmiddleware so that the sessions work .

+2

web :

Route::group(['middleware' => ['web']], function() {

. , - .

+1

Source: https://habr.com/ru/post/1654807/


All Articles