mercredi 11 juillet 2018

Laravel - set session from form input

I cannot display session value in my view. I only want to display it to see if it's correctly set inside the controller. Is it correctly set in controller? How can I check? I have this in view:

<div class="panel panel-success">
                <form action="" method="POST">
                    
                    @foreach($tables as  $data)                   
                    <button type="submit" name="tables" class="btn btn-primary" value="">
                        
                    </button>
                    @endforeach
                </form>
                
            </div>

This in ListController:

public function index() {
    $tables = DB::table('tables')->get();
    return view('welcome', compact('tables'));
}

public function getTable(Request $request) {
    $table_id = $request->get('tables');
    $request->session()->put('table_id', $table_id);
}

And this in web.php routes:

Route::get('/', 'ListController@index')->name('get_table');
Route::post('/', 'ListController@getTable');

I even tried

public function getTable(Request $request) {
    $request->session()->put('table_id', '1234');
}

Nothing shows up in the view at

What am I doing wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire