(laravel 5.4.36)
When I add 'middleware' => 'auth' to any of my routes, I get the three errors below. This only happens on my Production server. On my local it redirects to my login page as it should.
Example route:
Route::get('/credits', [
'middleware' => 'auth',
'as' => 'pages.credits',
'uses' => 'PagesController@credits'
]);
Symfony\Component\Debug\Exception\FatalThrowableError Call to a member function setCookie() on null
Symfony\Component\Debug\Exception\FatalThrowableError Type error: Argument 1 passed to Illuminate\Session\Middleware\StartSession::addCookieToResponse() must be an instance of Symfony\Component\HttpFoundation\Response, instance of Illuminate\View\View given, called in ../vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php on line 72
Symfony\Component\Debug\Exception\FatalThrowableError Type error: Argument 1 passed to Illuminate\Cookie\Middleware\EncryptCookies::encrypt() must be an instance of Symfony\Component\HttpFoundation\Response, instance of Illuminate\View\View given, called in ../vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php on line 59
/vendor/laravel/framework/illuminate/Auth/Middleware/Authenticate.php:
<?php
namespace Illuminate\Auth\Middleware;
use Closure;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Contracts\Auth\Factory as Auth;
class Authenticate
{
/**
* The authentication factory instance.
*
* @var \Illuminate\Contracts\Auth\Factory
*/
protected $auth;
/**
* Create a new middleware instance.
*
* @param \Illuminate\Contracts\Auth\Factory $auth
* @return void
*/
public function __construct(Auth $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string[] ...$guards
* @return mixed
*
* @throws \Illuminate\Auth\AuthenticationException
*/
public function handle($request, Closure $next, ...$guards)
{
$this->authenticate($guards);
return $next($request);
}
/**
* Determine if the user is logged in to any of the given guards.
*
* @param array $guards
* @return void
*
* @throws \Illuminate\Auth\AuthenticationException
*/
protected function authenticate(array $guards)
{
if (empty($guards)) {
return $this->auth->authenticate();
}
foreach ($guards as $guard) {
if ($this->auth->guard($guard)->check()) {
return $this->auth->shouldUse($guard);
}
}
throw new AuthenticationException('Unauthenticated.', $guards);
}
}