1

I was wondering if laravel has a function or constructor that always runs on all files.

I want to use this function (if it exist) to make the administrator logged in at all times while I am developing.

public function runsAlways()
{ 
   Auth::loginUsingId(1);
}
1
  • You can try middlewares Commented Dec 12, 2017 at 8:39

2 Answers 2

5

The boot function in the AppServiceProvider will be executed on every request.

But adding a custom provider or a middleware to all your routes would be a much cleaner solution.

Sign up to request clarification or add additional context in comments.

Comments

1

If you want the default for authentication to last for longer example two weekes , you can adjust the session lifetime in the session.php config file.

'lifetime' => 20160, // 60 * 24 * 14

And log in user on boot method as @Jerodev mentioned

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.