Im having a trouble binding a object in session to the router. This is in a fresh install of Laravel 5.2 and this is what i have:
So my routes file:
Route::resource('carts', 'CartsController');
In RouteServiceProvider:
public function map(Router $router)
{
$router->group(['namespace' => $this->namespace], function ($router) {
$router->bind('carts', function ($value) {
return Cart::get($value);
});
require app_path('Http/routes.php');
});
}
and this is in the Cart class:
public static function get($cartId)
{
if (\Session::has('carts.' . $cartId)) {
$cart = \Session::get('carts.' . $cartId);
} else {
$cart = new Cart($cartId);
}
return $cart;
}
So untill this step Session is not loaded. I tried to starting session manually by calling \Session::start(); but then it wouldn't get the expected data even if there are cart object in session. I also tried dd(\Session::all()), but it returns an empty array.
Does anyone know when to bind a object to route so that the session is also loaded?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire