Greetings, what I need is to keep some data sent from a form in an array that I store in Session de laravel, I'm doing it in the following way:
In the routes.php I have:
Route::bind('evento', function($slug){
return Deportes\Evento::where('slug', $slug)->first();
});
Route::get('tienda/agregar/{evento}', [
'as' => 'inscribir-evento',
'uses' => 'TiendaController@agregar']);
Route::get('tienda/{slug}', [
'as' => 'eventos-detalles',
'uses' => 'TiendaController@detalle']);
Route::post('tienda/inscribir/{evento}',[
'as'=> 'inscrito-inscribir',
'uses'=>'TiendaController@inscribir'
]);
Route::get('tienda/', 'TiendaController@index');
On my Controller:
public function index()
{
// $tienda = \Session::get('tienda');
dd(\Session::get('tienda'));
// return view('tienda.tienda', compact('tienda'));
}
public function agregar(Evento $evento){
$tienda = \Session::get('tienda');
if ($tienda = null) {
$tienda[$evento->slug] = $evento;
\Session::put('tienda', $tienda);
return view('tienda.inscribir', compact('tienda'));
}
else{
\Session::forget('tienda');
$tienda[$evento->slug] = $evento;
\Session::put('tienda', $tienda);
return view('tienda.inscribir', compact('tienda'));
}
}
public function inscribir(Evento $evento, Request $request){
$tienda = \Session::get('tienda');
$inscrito = [
'nombre'=>$request->get('nombre'),
'edad'=>$request->get('edad'),
'cedula'=>$request->get('cedula'),
];
$tienda[$inscrito['cedula']] = $inscrito;
\Session::put('tienda', $tienda);
dd(\Session::get('tienda'));
//return view('tienda.inscribir', compact('tienda'));
}
Now, when I register the person in the event, I add the person to the array by his / her cedula but when I go to see if it stays in the array somewhere else, the person does not appear ...
In fact what I need is to add several participants to the event ... the event is already in database, but the registered ones I want to have them temporarily during the whole session, until the conditions are fulfilled as it could be done?