Laravel-mongodb: (1/1) ErrorException Trying to get property 'headers' of non-object in VerifyCsrfToken.php line 158 at HandleExceptions->handleError(8, 'Trying to get property \'headers\' of non-object',

Created on 10 May 2018  Â·  14Comments  Â·  Source: jenssegers/laravel-mongodb

(1/1) ErrorExceptionTrying to get property 'headers' of non-object

in VerifyCsrfToken.php line 158
at HandleExceptions->handleError(8, 'Trying to get property \'headers\' of non-object',

question

Most helpful comment

I just got this error because in my middleware I was returning a route instead of 'return redirect()->route('')';

That resolved my case.

All 14 comments

I just got this error because in my middleware I was returning a route instead of 'return redirect()->route('')';

That resolved my case.

return redirect()->route('') in which file path, i have to change this?

On Mon, May 14, 2018 at 7:16 AM, Sacha QUESTEL notifications@github.com
wrote:

I just got this error because in my middleware I was returning a route
instead of 'return redirect()->route('')';

That resolved my case.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/jenssegers/laravel-mongodb/issues/1516#issuecomment-388674587,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVL6GYqiF_Vqf7WAQRjbb075Cbgj5oDYks5tyOIDgaJpZM4T5j1E
.

Depends on what you did in your application just before that happened. For me, I had just created custom middleware :

   public function handle($request, Closure $next)
    {
        if (!Auth::user()->admin) {
            return redirect(route('forum'));
        }
        return $next($request);
    }

But I was actually returning it like this :

   public function handle($request, Closure $next)
    {
        if (!Auth::user()->admin) {
            **return route('forum');**
        }
        return $next($request);
    }

Which was my problem that got me the same error. The custom middleware file is located in app/Http/Middleware

I think you might be somewhere returning directly a route or a view instead of redirecting...

Check what's triggered in your application when you try to go the the page that gives you this error, I mean the controller behind your route, or a middleware associated to the route.

Hope that will help you !

I am creating connection with mongodb, do you have any suggestions for this?

On Tue, May 15, 2018 at 2:13 AM, Sacha QUESTEL notifications@github.com
wrote:

Depends on what you did in your application just before that happened. For
me, I had just created custom middleware :

public function handle($request, Closure $next)
{
if (!Auth::user()->admin) {
return redirect(route('forum'));
}
return $next($request);
}

But I was actually returning it like this :

public function handle($request, Closure $next)
{
if (!Auth::user()->admin) {
return route('forum');
}
return $next($request);
}

Which was my problem that got me the same error. The custom middleware
file is located in app/Http/Middleware

I think you might be returning directly a route or a view instead of
redirecting...

Hope that will help you !

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/jenssegers/laravel-mongodb/issues/1516#issuecomment-388956215,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVL6GVF-mcaeP-Z3t2gmV3lsiJi5PqdFks5tyexzgaJpZM4T5j1E
.

Do you have example for crud operations and login/register with mongodb?

On Tue, May 15, 2018 at 12:26 PM, Sagar Jain stardesign041@gmail.com
wrote:

I am creating connection with mongodb, do you have any suggestions for
this?

On Tue, May 15, 2018 at 2:13 AM, Sacha QUESTEL notifications@github.com
wrote:

Depends on what you did in your application just before that happened.
For me, I had just created custom middleware :

public function handle($request, Closure $next)
{
if (!Auth::user()->admin) {
return redirect(route('forum'));
}
return $next($request);
}

But I was actually returning it like this :

public function handle($request, Closure $next)
{
if (!Auth::user()->admin) {
return route('forum');
}
return $next($request);
}

Which was my problem that got me the same error. The custom middleware
file is located in app/Http/Middleware

I think you might be returning directly a route or a view instead of
redirecting...

Hope that will help you !

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/jenssegers/laravel-mongodb/issues/1516#issuecomment-388956215,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVL6GVF-mcaeP-Z3t2gmV3lsiJi5PqdFks5tyexzgaJpZM4T5j1E
.

  1. $statement = $this->prepared($this->getPdoForSelect($useReadPdo)
  2. ->prepare($query));

vendor\laravel\framework\src\Illuminate\Database\Connection.php

Symfony \ Component \ Debug \ Exception \FatalThrowableError (E_ERROR)
Call to a member function prepare() on null

On Tue, May 15, 2018 at 3:15 PM, Sagar Jain stardesign041@gmail.com wrote:

Do you have example for crud operations and login/register with mongodb?

On Tue, May 15, 2018 at 12:26 PM, Sagar Jain stardesign041@gmail.com
wrote:

I am creating connection with mongodb, do you have any suggestions for
this?

On Tue, May 15, 2018 at 2:13 AM, Sacha QUESTEL notifications@github.com
wrote:

Depends on what you did in your application just before that happened.
For me, I had just created custom middleware :

public function handle($request, Closure $next)
{
if (!Auth::user()->admin) {
return redirect(route('forum'));
}
return $next($request);
}

But I was actually returning it like this :

public function handle($request, Closure $next)
{
if (!Auth::user()->admin) {
return route('forum');
}
return $next($request);
}

Which was my problem that got me the same error. The custom middleware
file is located in app/Http/Middleware

I think you might be returning directly a route or a view instead of
redirecting...

Hope that will help you !

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/jenssegers/laravel-mongodb/issues/1516#issuecomment-388956215,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVL6GVF-mcaeP-Z3t2gmV3lsiJi5PqdFks5tyexzgaJpZM4T5j1E
.

For your second error, check this :
https://stackoverflow.com/questions/28592400/fatal-error-call-to-a-member-function-prepare-on-null?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

Have you done the configuration correctly according to this ?

https://github.com/jenssegers/laravel-mongodb#configuration

Honestly I haven't used mongodb with Laravel so I can't tell you more about it.

For your second error, check this : what i have to check?

On Tue, May 15, 2018 at 8:11 PM, Sacha QUESTEL notifications@github.com
wrote:

For your second error, check this :

https://stackoverflow.com/questions/28592400/fatal-error-call-to-a-member-function-prepare-on-null?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

Have you done the configuration correctly according to this ?

https://github.com/jenssegers/laravel-mongodb#configuration

Honestly I haven't used mongodb with Laravel so I can't tell you more
about it.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/jenssegers/laravel-mongodb/issues/1516#issuecomment-389192160,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVL6GWgELEYPUpEo9jNQK7YdrqdoPyT0ks5tyukxgaJpZM4T5j1E
.

FYI, I had this exact issue, and it was because of the following:

1/ I was using multiple auth guards (e.g. admin and front end user)
2/ I had overridden the unauthenticated method on the exception handler, and had logic to perform different actions for different guards
3/ I hadn't specified an action for the guard in question, and therefore this method was returning null

Sacha QUESTEL @.*> wrote: I just got this error because in my middleware I was returning a route instead of 'return redirect()->route('')';

Lol oops, I just triggered this error by having:

return request()->json(['asdf' => 'asdf], 401);

I didn't notice it because request looks so similar to response. Also unfortunately VS Code and PHP intelephense didn't lint it.

Changed it to the correct:

return response()->json(['asdf' => 'asdf], 401);

I was also facing the same problem, but mine was resolved after I added return $next($request); line after the "if-else" condition

/**

 * Add the CSRF token to the response cookies.

 *

 * @param  \Illuminate\Http\Request  $request

 * @param  \Symfony\Component\HttpFoundation\Response  $response

 * @return \Symfony\Component\HttpFoundation\Response

 */

protected function addCookieToResponse($request, $response)

{

    $config = config('session');



    if ($response instanceof Responsable) {

        $response = $response->toResponse($request);

    }



    $response->headers->setCookie(

        new Cookie(

            'XSRF-TOKEN', $request->session()->token(), $this->availableAt(60 * $config['lifetime']),

            $config['path'], $config['domain'], $config['secure'], false, false, $config['same_site'] ?? null

        )

    );



    return $response;

}



/**

 * Determine if the cookie contents should be serialized.

 *

 * @return bool

 */

public static function serialized()

Trying to get property 'headers' of non-object

Was this page helpful?
0 / 5 - 0 ratings

Related issues

viacheslavpleshkov picture viacheslavpleshkov  Â·  3Comments

sebastiaanluca picture sebastiaanluca  Â·  3Comments

BlakeGardner picture BlakeGardner  Â·  3Comments

lgt picture lgt  Â·  3Comments

naveedyasin picture naveedyasin  Â·  3Comments