1

My laravel middleware is behaving funny in that anytime I use a middleware, either custom or any default laravel middleware,

I get this error

Object of class stdClass could not be converted to string

and whenever I trace the file the error is coming from, it targets

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

James Z
  • 12,209
  • 10
  • 24
  • 44
Kingsley Akindele
  • 311
  • 1
  • 2
  • 13
  • 1
    Please share your code where error comes from – A.A Noman Sep 14 '21 at 07:37
  • What line in Illuminate/Database/Connection.php is causing that error? – apokryfos Sep 14 '21 at 07:38
  • The error comes from line 603 within the Illuminate/Database/Connection.php file – Kingsley Akindele Sep 14 '21 at 07:42
  • your laravel version? and php version? – Ariful Islam Sep 14 '21 at 07:58
  • That error indicates you're trying to perform a query in the database but are passing an object where a string is expected. Since you are saying this is happening every time you try to use any middleware (and since all requests use middleware) I'm going to assume the error originates from a service provider or any sort of code that always runs – apokryfos Sep 14 '21 at 08:38

1 Answers1

0

I already figured out the issue. The issue turned out to be that there was a bug in my JWT identifier within my Model.

i had this

{
  return [
    'token' => $this->getKey(),
    'ttl' => config('jwt.ttl')
  ];
}

instead of this

public function getJWTIdentifier()
{
  return $this->getKey();
}

btw, I am using tymon/jwt Thanks everyone.

Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
Kingsley Akindele
  • 311
  • 1
  • 2
  • 13