1

In my Laravel-5.8 project, I am trying to myconfig.php inside app/config. I want it to return this array

return ['default_domain_name' => 'myapp']

as in: app/config/myconfig.php

I want to call it inside the middleware I created

class VerifyDomain
{
    public function handle($request, Closure $next)
    {
        $request->get('domain_name', $this->getBaseDomain());

        $company = Company::where('subdomain', $subdomain)->firstOrFail();

        $request->session()->put('subdomain', $company);

        return $next($request);
    } 

    protected function getBaseDomain()
    {
        return config('myconfig.default_domain_name', 'myapp');
    }
}

How do I write to return:

return ['default_domain_name' => 'myapp']

inside app/config/myconfig.php

Thanks

2
  • what do you get if you do a var_dump(config('myconfig')) Commented Feb 4, 2021 at 12:42
  • @FrédéricKlee - var_dump(config('myconfig')) returns null. How do I register and reference app/config/myconfig.php. This what I have in myconfig.php: <?php return [ 'default_domain_name' => 'myapp' ]; Commented Feb 4, 2021 at 13:15

1 Answer 1

1

If your config looks like this:

return [
    'default_domain_name' => 'myapp',
]

... and your config file has myconfig.php name...

Just call

config('myconfig'); // returns ['default_domain_name' => 'myapp']
Sign up to request clarification or add additional context in comments.

3 Comments

var_dump(config('myconfig')) returns null. How do I register and reference app/config/myconfig.php. This what I have in myconfig.php: <?php return [ 'default_domain_name' => 'myapp', ];
if your config file is in folder "config" you have nothing to do, but clear cache config maybe !?
thank you I don't know why I didn't test this maybe I'm tired.

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.