2

I'm trying to fetch data from sessions when I run a command in my console, but session always returns an empty array!

php artisan command:mycommand

Below is how I'm trying to get the session:

//returns empty array
$session = session()->all();

Any ideas?

1 Answer 1

1

Session are used in the context of HTTP protocol. There is no such session using CLI. However, if your php artisan command is triggered in the context of an HTTP request, you could pass data to your command using arguments.

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

3 Comments

Thanks for the answer! That is the problem! I don't have the request! I'm using \Illuminate\Console\Scheduling\Schedule!
And why would you need session data in a scheduled artisan command ?
Let's say you obtain auth token from a 3rd party. It would be more efficient to share this token instead of having each class obtain the same token.

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.