-
I I'm trying to make the following feature test:
Pseudocode:
The controller:
Output of the test:
Expected output:
The cause of the "problem" can be found in RequestGuard.php
By default, during the same session, it will return the "cached" user, so it doesn't query the database each time you use How do I make the second requests a different requests, so that p.s. Im using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You can reload a fresh model instance from the database using the The controller: public function user()
{
$user = auth()->user()->fresh();
echo $user->username . PHP_EOL;
} This ensures a new user instance every time you hit the controller function. |
Beta Was this translation helpful? Give feedback.
-
Solution: refresh the user only when the route is called via unit testing. Done by using /app/Http/Middleware/UnitTestMiddleware.php
and add the middleware to the |
Beta Was this translation helpful? Give feedback.
Solution: refresh the user only when the route is called via unit testing. Done by using
app()->runningUnitTests()
in middleware./app/Http/Middleware/UnitTestMiddleware.php
and add the middleware to the
$middleware
inapp/Http/Kernel.php