Well, first, there are a few things that I would change or a few things that I just don't understand.
-
You named your function get. It's kind of confusing because it behaves vastly different from Laravel's own get method.
-
I'm assuming $cartId is an integer. Laravel model's constructor function accepts an array, not an integer.
Finally, regarding your problem, you cannot use sessions inside the RouteServiceProvider because Laravel sessions haven't even been initialized yet. There's a huge discussion on that here:
https://github.com/laravel/framework/issues/6118
Basically, people are saying that it doesn't make sense to run route model binding before middlewares (which is what initiates the sessions). Some are arguing that it does make sense.
In L5.2, this lifecycle kind of caused other issues with the new implicit model binding.
Anyway, a workaround is to move the web middleware into the global middleware stack. This means getting rid of your web middleware. So open up app\Http\Kernel.php and change these two arrays:
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
];
protected $middlewareGroups = [
'api' => [
'throttle:60,1',
],
];
Also, make sure to remove the web group in your routes file.