#session error
10 messages · Page 1 of 1 (latest)
Illuminate\Database\QueryException: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "sessions" does not exist
is this due to laravel 11?
You're using the database session driver
Hi, let's discuss about the issue in more detail.
I want to know the issue in deeply because there can be several reasons.
alrightt which detail can i provide first? sorry cuz im new here
i did this on my User model so i can do Auth::login($user)
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class User extends Model implements Authenticatable
{
and on middleware i did this :
public function handle(Request $request, Closure $next): Response
{
$token = $request->header("Authorization");
$authenticate = true;
if (!$token) {
$authenticate = false;
};
$user = User::where("token", $token)->first();
if (!$user) {
$authenticate = false;
} else {
Auth::login($user);
}
if ($authenticate) {
return $next($request);
} else {
return response()->json([
"errors" => [
"message" => "Unauthorized"
]
])->setStatusCode(401);
}
}
and then when i try to do unit test, it gives the 500 error (the session one)
public function testGetUserSuccess()
{
$this->seed(UserSeeder::class);
$this->get("/api/auth/users/current", [
"Authorization" => "test"
])->assertStatus(200)
->assertJson([
"data"=> [
"username" => "test",
"name"=> "test"
]
]);
}
i dont really understand this, how can i like disable it or something?
https://laravel.com/docs/11.x/session#driver-prerequisites
please have a look at the docs, as Robert mentioned at #1218658166770765955 message, you are using the database driver