Issue
In the session.php I use the helper function url() for creating a dynamic domain name. This way when I move to the real server I won't have to change the domain name. It looks like this:
'domain' => url(''),
Everything works fine in the browser but when I use any php artisan or composer commands from the terminal it will give me this error:
PHP Fatal error: Uncaught ReflectionException: Class log does not exist in /vendor/laravel/framework/src/Illuminate/Container/Container.php:738
Trying it like this doesn't seem to help
'domain' => @url(''),
Is there anything to be done? I'm using Laravel 5.2
Solution
That's because the url
helper function uses the Illuminate\Routing\UrlGenerator
class to generate the URL and that class requires a Request
instance to be injected. And in your particular case the problem there is no request context for an artisan command.
My suggestion is to use an environment variable. So in your .env
file you can have:
SESSION_DOMAIN=mydomain.com
And in your config/session.php
file you can have:
'domain' => env('SESSION_DOMAIN'),
You can safely use the env
helper method as it has no special dependencies.
If you really want to use the dynamic approach, you can set the cookie domain via a conditional assignment that only sets the cookie domain using url
if the application is not running in console mode. So having this will do the trick:
'domain' => app()->runningInConsole() ? null : parse_url(url(''), PHP_URL_HOST),
Answered By - Bogdan
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.